1
0
Fork 0

Added create index and change collection marker creation.

This commit is contained in:
Dan Larkin 2017-04-26 15:23:25 -04:00
parent 5ef52aefe8
commit f8efe6e627
4 changed files with 100 additions and 40 deletions

View File

@ -341,6 +341,11 @@ std::shared_ptr<Index> RocksDBCollection::createIndex(
->forceSyncProperties();
VPackBuilder builder = _logicalCollection->toVelocyPackIgnore(
{"path", "statusString"}, true, /*forPersistence*/ false);
auto rtrx = rocksTransaction(trx);
rtrx->PutLogData(
RocksDBLogValue::IndexCreate(_logicalCollection->vocbase()->id(),
_logicalCollection->cid(), info)
.slice());
_logicalCollection->updateProperties(builder.slice(), doSync);
}
created = true;

View File

@ -675,7 +675,17 @@ void RocksDBEngine::destroyCollection(TRI_vocbase_t* vocbase,
void RocksDBEngine::changeCollection(
TRI_vocbase_t* vocbase, TRI_voc_cid_t id,
arangodb::LogicalCollection const* parameters, bool doSync) {
createCollection(vocbase, id, parameters);
VPackBuilder builder = parameters->toVelocyPackIgnore(
{"path", "statusString"}, /*translate cid*/ true,
/*for persistence*/ true);
int res = writeCreateCollectionMarker(
vocbase->id(), id, builder.slice(),
RocksDBLogValue::CollectionChange(vocbase->id(), id));
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res);
}
}
arangodb::Result RocksDBEngine::renameCollection(

View File

@ -30,7 +30,8 @@
using namespace arangodb;
using namespace arangodb::rocksutils;
RocksDBLogValue RocksDBLogValue::BeginTransaction(TRI_voc_tick_t dbid, TRI_voc_tid_t tid) {
RocksDBLogValue RocksDBLogValue::BeginTransaction(TRI_voc_tick_t dbid,
TRI_voc_tid_t tid) {
return RocksDBLogValue(RocksDBLogType::BeginTransaction, dbid, tid);
}
@ -46,36 +47,46 @@ RocksDBLogValue RocksDBLogValue::CollectionCreate(TRI_voc_cid_t cid) {
return RocksDBLogValue(RocksDBLogType::CollectionCreate, cid);
}
RocksDBLogValue RocksDBLogValue::CollectionDrop(TRI_voc_tick_t dbid, TRI_voc_cid_t cid) {
RocksDBLogValue RocksDBLogValue::CollectionDrop(TRI_voc_tick_t dbid,
TRI_voc_cid_t cid) {
return RocksDBLogValue(RocksDBLogType::CollectionDrop, dbid, cid);
}
RocksDBLogValue RocksDBLogValue::CollectionRename(TRI_voc_tick_t dbid, TRI_voc_cid_t cid, std::string const& newName) {
RocksDBLogValue RocksDBLogValue::CollectionRename(TRI_voc_tick_t dbid,
TRI_voc_cid_t cid,
std::string const& newName) {
return RocksDBLogValue(RocksDBLogType::CollectionRename, dbid, cid, newName);
}
RocksDBLogValue RocksDBLogValue::CollectionChange(TRI_voc_tick_t dbid, TRI_voc_cid_t cid) {
RocksDBLogValue RocksDBLogValue::CollectionChange(TRI_voc_tick_t dbid,
TRI_voc_cid_t cid) {
return RocksDBLogValue(RocksDBLogType::CollectionChange, dbid, cid);
}
RocksDBLogValue RocksDBLogValue::IndexCreate(TRI_voc_tick_t dbid, TRI_voc_cid_t cid, TRI_idx_iid_t iid) {
return RocksDBLogValue(RocksDBLogType::IndexCreate, dbid, cid, iid);
RocksDBLogValue RocksDBLogValue::IndexCreate(TRI_voc_tick_t dbid,
TRI_voc_cid_t cid,
VPackSlice const& indexInfo) {
return RocksDBLogValue(RocksDBLogType::IndexCreate, dbid, cid, indexInfo);
}
RocksDBLogValue RocksDBLogValue::IndexDrop(TRI_voc_tick_t dbid, TRI_voc_cid_t cid, TRI_idx_iid_t iid) {
RocksDBLogValue RocksDBLogValue::IndexDrop(TRI_voc_tick_t dbid,
TRI_voc_cid_t cid,
TRI_idx_iid_t iid) {
return RocksDBLogValue(RocksDBLogType::IndexDrop, dbid, cid, iid);
}
RocksDBLogValue RocksDBLogValue::ViewCreate(TRI_voc_cid_t cid, TRI_idx_iid_t iid) {
RocksDBLogValue RocksDBLogValue::ViewCreate(TRI_voc_cid_t cid,
TRI_idx_iid_t iid) {
return RocksDBLogValue(RocksDBLogType::ViewCreate, cid, iid);
}
RocksDBLogValue RocksDBLogValue::ViewDrop(TRI_voc_cid_t cid, TRI_idx_iid_t iid) {
RocksDBLogValue RocksDBLogValue::ViewDrop(TRI_voc_cid_t cid,
TRI_idx_iid_t iid) {
return RocksDBLogValue(RocksDBLogType::ViewDrop, cid, iid);
}
RocksDBLogValue RocksDBLogValue::DocumentRemove(arangodb::StringRef const& key) {
RocksDBLogValue RocksDBLogValue::DocumentRemove(
arangodb::StringRef const& key) {
return RocksDBLogValue(RocksDBLogType::DocumentRemove, key);
}
@ -90,28 +101,28 @@ RocksDBLogValue::RocksDBLogValue(RocksDBLogType type) : _buffer() {
}
}
RocksDBLogValue::RocksDBLogValue(RocksDBLogType type, uint64_t val) : _buffer() {
RocksDBLogValue::RocksDBLogValue(RocksDBLogType type, uint64_t val)
: _buffer() {
switch (type) {
case RocksDBLogType::DatabaseDrop:
case RocksDBLogType::CollectionCreate: {
_buffer.reserve(sizeof(RocksDBLogType) + sizeof(uint64_t));
_buffer += static_cast<char>(type);
uint64ToPersistent(_buffer, val);// database or collection ID
uint64ToPersistent(_buffer, val); // database or collection ID
break;
}
default:
THROW_ARANGO_EXCEPTION(TRI_ERROR_BAD_PARAMETER);
}
}
RocksDBLogValue::RocksDBLogValue(RocksDBLogType type, uint64_t dbId, uint64_t cid)
RocksDBLogValue::RocksDBLogValue(RocksDBLogType type, uint64_t dbId,
uint64_t cid)
: _buffer() {
switch (type) {
case RocksDBLogType::BeginTransaction:
case RocksDBLogType::CollectionChange:
case RocksDBLogType::CollectionChange:
case RocksDBLogType::CollectionDrop: {
_buffer.reserve(sizeof(RocksDBLogType) + sizeof(uint64_t) * 2);
_buffer += static_cast<char>(type);
@ -125,10 +136,10 @@ RocksDBLogValue::RocksDBLogValue(RocksDBLogType type, uint64_t dbId, uint64_t ci
}
}
RocksDBLogValue::RocksDBLogValue(RocksDBLogType type, uint64_t dbId, uint64_t cid, uint64_t iid)
RocksDBLogValue::RocksDBLogValue(RocksDBLogType type, uint64_t dbId,
uint64_t cid, uint64_t iid)
: _buffer() {
switch (type) {
case RocksDBLogType::IndexCreate:
case RocksDBLogType::IndexDrop: {
_buffer.reserve(sizeof(RocksDBLogType) + sizeof(uint64_t) * 3);
_buffer += static_cast<char>(type);
@ -142,12 +153,33 @@ RocksDBLogValue::RocksDBLogValue(RocksDBLogType type, uint64_t dbId, uint64_t ci
}
}
RocksDBLogValue::RocksDBLogValue(RocksDBLogType type, uint64_t dbId, uint64_t cid, std::string const& data)
: _buffer() {
RocksDBLogValue::RocksDBLogValue(RocksDBLogType type, uint64_t dbId,
uint64_t cid, VPackSlice const& indexInfo)
: _buffer() {
switch (type) {
case RocksDBLogType::IndexCreate: {
_buffer.reserve(sizeof(RocksDBLogType) + (sizeof(uint64_t) * 2) +
indexInfo.byteSize());
_buffer += static_cast<char>(type);
uint64ToPersistent(_buffer, dbId);
uint64ToPersistent(_buffer, cid);
_buffer.append(reinterpret_cast<char const*>(indexInfo.begin()),
indexInfo.byteSize());
break;
}
default:
THROW_ARANGO_EXCEPTION(TRI_ERROR_BAD_PARAMETER);
}
}
RocksDBLogValue::RocksDBLogValue(RocksDBLogType type, uint64_t dbId,
uint64_t cid, std::string const& data)
: _buffer() {
if (type != RocksDBLogType::CollectionRename) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_BAD_PARAMETER);
}
_buffer.reserve(sizeof(RocksDBLogType) + sizeof(uint64_t) * 2 + data.length());
_buffer.reserve(sizeof(RocksDBLogType) + sizeof(uint64_t) * 2 +
data.length());
_buffer += static_cast<char>(type);
uint64ToPersistent(_buffer, dbId);
uint64ToPersistent(_buffer, cid);
@ -155,7 +187,7 @@ RocksDBLogValue::RocksDBLogValue(RocksDBLogType type, uint64_t dbId, uint64_t ci
}
RocksDBLogValue::RocksDBLogValue(RocksDBLogType type, StringRef const& data)
: _buffer() {
: _buffer() {
switch (type) {
case RocksDBLogType::DocumentRemove: {
_buffer.reserve(data.length() + sizeof(RocksDBLogType));
@ -187,8 +219,8 @@ TRI_voc_tid_t RocksDBLogValue::transactionId(rocksdb::Slice const& slice) {
TRI_ASSERT(slice.size() >= sizeof(RocksDBLogType) + sizeof(uint64_t));
RocksDBLogType type = static_cast<RocksDBLogType>(slice.data()[0]);
if (type == RocksDBLogType::BeginTransaction) {
return uint64FromPersistent(slice.data() + sizeof(TRI_voc_tick_t)
+ sizeof(RocksDBLogType));
return uint64FromPersistent(slice.data() + sizeof(TRI_voc_tick_t) +
sizeof(RocksDBLogType));
} else {
THROW_ARANGO_EXCEPTION(TRI_ERROR_BAD_PARAMETER);
}

View File

@ -24,11 +24,14 @@
#ifndef ARANGO_ROCKSDB_ROCKSDB_LOG_VALUE_H
#define ARANGO_ROCKSDB_ROCKSDB_LOG_VALUE_H 1
#include "Basics/Common.h"
#include "Basics/StringRef.h"
#include "RocksDBEngine/RocksDBTypes.h"
#include "VocBase/voc-types.h"
#include <rocksdb/slice.h>
#include <velocypack/Slice.h>
#include <velocypack/velocypack-aliases.h>
namespace arangodb {
@ -40,20 +43,28 @@ class RocksDBLogValue {
// parameter in an appropriate format into the underlying string buffer.
//----------------------------------------------------------------------------
static RocksDBLogValue BeginTransaction(TRI_voc_tick_t vocbaseId, TRI_voc_tid_t trxId);
static RocksDBLogValue BeginTransaction(TRI_voc_tick_t vocbaseId,
TRI_voc_tid_t trxId);
static RocksDBLogValue DatabaseCreate();
static RocksDBLogValue DatabaseDrop(TRI_voc_tick_t vocbaseId);
static RocksDBLogValue CollectionCreate(TRI_voc_tick_t vocbaseId);
static RocksDBLogValue CollectionDrop(TRI_voc_tick_t vocbaseId, TRI_voc_cid_t cid);
static RocksDBLogValue CollectionRename(TRI_voc_tick_t vocbaseId, TRI_voc_cid_t cid, std::string const& newName);
static RocksDBLogValue CollectionChange(TRI_voc_tick_t vocbaseId, TRI_voc_cid_t cid);
static RocksDBLogValue IndexCreate(TRI_voc_tick_t vocbaseId, TRI_voc_cid_t cid, TRI_idx_iid_t indexId);
static RocksDBLogValue IndexDrop(TRI_voc_tick_t vocbaseId, TRI_voc_cid_t cid, TRI_idx_iid_t indexId);
static RocksDBLogValue CollectionDrop(TRI_voc_tick_t vocbaseId,
TRI_voc_cid_t cid);
static RocksDBLogValue CollectionRename(TRI_voc_tick_t vocbaseId,
TRI_voc_cid_t cid,
std::string const& newName);
static RocksDBLogValue CollectionChange(TRI_voc_tick_t vocbaseId,
TRI_voc_cid_t cid);
static RocksDBLogValue IndexCreate(TRI_voc_tick_t vocbaseId,
TRI_voc_cid_t cid,
VPackSlice const& indexInfo);
static RocksDBLogValue IndexDrop(TRI_voc_tick_t vocbaseId, TRI_voc_cid_t cid,
TRI_idx_iid_t indexId);
static RocksDBLogValue ViewCreate(TRI_voc_cid_t, TRI_idx_iid_t);
static RocksDBLogValue ViewDrop(TRI_voc_cid_t, TRI_idx_iid_t);
static RocksDBLogValue DocumentRemove(arangodb::StringRef const&);
public:
@ -74,22 +85,24 @@ class RocksDBLogValue {
//////////////////////////////////////////////////////////////////////////////
/// @brief Returns a reference to the underlying string buffer.
//////////////////////////////////////////////////////////////////////////////
std::string const& string() const { return _buffer; } // to be used with put
std::string const& string() const { return _buffer; } // to be used with put
/*VPackSlice slice() const { return VPackSlice(
reinterpret_cast<uint8_t const*>(_buffer.data())
); }*/ // return a slice
); }*/ // return a slice
RocksDBLogType type() const {
return static_cast<RocksDBLogType>(*(_buffer.data()));
}
rocksdb::Slice slice() const { return rocksdb::Slice(_buffer); }
private:
explicit RocksDBLogValue(RocksDBLogType type);
RocksDBLogValue(RocksDBLogType type, uint64_t);
RocksDBLogValue(RocksDBLogType type, uint64_t, uint64_t);
RocksDBLogValue(RocksDBLogType type, uint64_t, uint64_t, uint64_t);
RocksDBLogValue(RocksDBLogType type, uint64_t, uint64_t, std::string const& data);
RocksDBLogValue(RocksDBLogType type, uint64_t, uint64_t, VPackSlice const&);
RocksDBLogValue(RocksDBLogType type, uint64_t, uint64_t,
std::string const& data);
RocksDBLogValue(RocksDBLogType type, StringRef const& data);
private: