mirror of https://gitee.com/bigwinds/arangodb
Moved keyGenerator into physicalCollection. Only used when actually storing data.
This commit is contained in:
parent
5d452edec6
commit
853394da79
|
@ -167,7 +167,7 @@ int MMFilesCollection::OpenIteratorHandleDocumentMarker(TRI_df_marker_t const* m
|
||||||
if (state->_trackKeys) {
|
if (state->_trackKeys) {
|
||||||
VPackValueLength length;
|
VPackValueLength length;
|
||||||
char const* p = keySlice.getString(length);
|
char const* p = keySlice.getString(length);
|
||||||
collection->keyGenerator()->track(p, length);
|
physical->keyGenerator()->track(p, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
++state->_documents;
|
++state->_documents;
|
||||||
|
@ -262,7 +262,7 @@ int MMFilesCollection::OpenIteratorHandleDeletionMarker(TRI_df_marker_t const* m
|
||||||
if (state->_trackKeys) {
|
if (state->_trackKeys) {
|
||||||
VPackValueLength length;
|
VPackValueLength length;
|
||||||
char const* p = keySlice.getString(length);
|
char const* p = keySlice.getString(length);
|
||||||
collection->keyGenerator()->track(p, length);
|
physical->keyGenerator()->track(p, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
++state->_deletions;
|
++state->_deletions;
|
||||||
|
@ -400,11 +400,13 @@ MMFilesCollection::MMFilesCollection(LogicalCollection* collection, VPackSlice c
|
||||||
setCompactionStatus("compaction not yet started");
|
setCompactionStatus("compaction not yet started");
|
||||||
}
|
}
|
||||||
|
|
||||||
MMFilesCollection::MMFilesCollection(LogicalCollection* logical, PhysicalCollection* physical):
|
MMFilesCollection::MMFilesCollection(LogicalCollection* logical,
|
||||||
PhysicalCollection(logical, VPackSlice::emptyObjectSlice()),
|
PhysicalCollection* physical)
|
||||||
_ditches(logical)
|
: PhysicalCollection(logical, VPackSlice::emptyObjectSlice()),
|
||||||
{
|
_ditches(logical) {
|
||||||
|
_keyOptions = VPackBuilder::clone(physical->keyOptions()).steal();
|
||||||
MMFilesCollection& mmfiles = *static_cast<MMFilesCollection*>(physical);
|
MMFilesCollection& mmfiles = *static_cast<MMFilesCollection*>(physical);
|
||||||
|
_keyGenerator.reset(KeyGenerator::factory(mmfiles.keyOptions()));
|
||||||
_initialCount = mmfiles._initialCount;
|
_initialCount = mmfiles._initialCount;
|
||||||
_revisionError = mmfiles._revisionError;
|
_revisionError = mmfiles._revisionError;
|
||||||
_lastRevision = mmfiles._lastRevision;
|
_lastRevision = mmfiles._lastRevision;
|
||||||
|
|
|
@ -95,7 +95,7 @@ class MMFilesCollection final : public PhysicalCollection {
|
||||||
_documents(0),
|
_documents(0),
|
||||||
_operations(0),
|
_operations(0),
|
||||||
_initialCount(-1),
|
_initialCount(-1),
|
||||||
_trackKeys(collection->keyGenerator()->trackKeys()) {
|
_trackKeys(collection->getPhysical()->keyGenerator()->trackKeys()) {
|
||||||
TRI_ASSERT(collection != nullptr);
|
TRI_ASSERT(collection != nullptr);
|
||||||
TRI_ASSERT(trx != nullptr);
|
TRI_ASSERT(trx != nullptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1347,7 +1347,7 @@ static void JS_PropertiesVocbaseCol(
|
||||||
|
|
||||||
result->Set(TRI_V8_ASCII_STRING("numberOfShards"),
|
result->Set(TRI_V8_ASCII_STRING("numberOfShards"),
|
||||||
v8::Number::New(isolate, c->numberOfShards()));
|
v8::Number::New(isolate, c->numberOfShards()));
|
||||||
auto keyOpts = info->keyOptions();
|
auto keyOpts = info->getPhysical()->keyOptions();
|
||||||
if (keyOpts.isObject() && keyOpts.length() > 0) {
|
if (keyOpts.isObject() && keyOpts.length() > 0) {
|
||||||
TRI_GET_GLOBAL_STRING(KeyOptionsKey);
|
TRI_GET_GLOBAL_STRING(KeyOptionsKey);
|
||||||
result->Set(KeyOptionsKey, TRI_VPackToV8(isolate, keyOpts)->ToObject());
|
result->Set(KeyOptionsKey, TRI_VPackToV8(isolate, keyOpts)->ToObject());
|
||||||
|
@ -1452,7 +1452,7 @@ static void JS_PropertiesVocbaseCol(
|
||||||
try {
|
try {
|
||||||
VPackBuilder optionsBuilder;
|
VPackBuilder optionsBuilder;
|
||||||
optionsBuilder.openObject();
|
optionsBuilder.openObject();
|
||||||
collection->keyGenerator()->toVelocyPack(optionsBuilder);
|
collection->getPhysical()->keyGenerator()->toVelocyPack(optionsBuilder);
|
||||||
optionsBuilder.close();
|
optionsBuilder.close();
|
||||||
result->Set(KeyOptionsKey,
|
result->Set(KeyOptionsKey,
|
||||||
TRI_VPackToV8(isolate, optionsBuilder.slice())->ToObject());
|
TRI_VPackToV8(isolate, optionsBuilder.slice())->ToObject());
|
||||||
|
|
|
@ -116,18 +116,6 @@ static std::string const ReadStringValue(VPackSlice info,
|
||||||
}
|
}
|
||||||
return Helper::getStringValue(info, name, def);
|
return Helper::getStringValue(info, name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::shared_ptr<arangodb::velocypack::Buffer<uint8_t> const>
|
|
||||||
CopySliceValue(VPackSlice info, std::string const& name) {
|
|
||||||
if (!info.isObject()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
info = info.get(name);
|
|
||||||
if (info.isNone()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return VPackBuilder::clone(info).steal();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief This the "copy" constructor used in the cluster
|
/// @brief This the "copy" constructor used in the cluster
|
||||||
|
@ -149,7 +137,6 @@ LogicalCollection::LogicalCollection(LogicalCollection const& other)
|
||||||
_isSystem(other.isSystem()),
|
_isSystem(other.isSystem()),
|
||||||
_isVolatile(other.isVolatile()),
|
_isVolatile(other.isVolatile()),
|
||||||
_waitForSync(other.waitForSync()),
|
_waitForSync(other.waitForSync()),
|
||||||
_keyOptions(other._keyOptions),
|
|
||||||
_version(other._version),
|
_version(other._version),
|
||||||
_indexBuckets(other.indexBuckets()),
|
_indexBuckets(other.indexBuckets()),
|
||||||
_indexes(),
|
_indexes(),
|
||||||
|
@ -160,10 +147,7 @@ LogicalCollection::LogicalCollection(LogicalCollection const& other)
|
||||||
_vocbase(other.vocbase()),
|
_vocbase(other.vocbase()),
|
||||||
_cleanupIndexes(0),
|
_cleanupIndexes(0),
|
||||||
_persistentIndexes(0),
|
_persistentIndexes(0),
|
||||||
_physical(other.getPhysical()->clone(this,other.getPhysical())),
|
_physical(other.getPhysical()->clone(this, other.getPhysical())) {
|
||||||
_keyGenerator() {
|
|
||||||
_keyGenerator.reset(KeyGenerator::factory(other.keyOptions()));
|
|
||||||
|
|
||||||
if (ServerState::instance()->isDBServer() ||
|
if (ServerState::instance()->isDBServer() ||
|
||||||
!ServerState::instance()->isRunningInCluster()) {
|
!ServerState::instance()->isRunningInCluster()) {
|
||||||
_followers.reset(new FollowerInfo(this));
|
_followers.reset(new FollowerInfo(this));
|
||||||
|
@ -198,7 +182,6 @@ LogicalCollection::LogicalCollection(TRI_vocbase_t* vocbase,
|
||||||
Helper::readBooleanValue(info, "isSystem", false)),
|
Helper::readBooleanValue(info, "isSystem", false)),
|
||||||
_isVolatile(Helper::readBooleanValue(info, "isVolatile", false)),
|
_isVolatile(Helper::readBooleanValue(info, "isVolatile", false)),
|
||||||
_waitForSync(Helper::readBooleanValue(info, "waitForSync", false)),
|
_waitForSync(Helper::readBooleanValue(info, "waitForSync", false)),
|
||||||
_keyOptions(CopySliceValue(info, "keyOptions")),
|
|
||||||
_version(Helper::readNumericValue<uint32_t>(info, "version", currentVersion())),
|
_version(Helper::readNumericValue<uint32_t>(info, "version", currentVersion())),
|
||||||
_indexBuckets(Helper::readNumericValue<uint32_t>(
|
_indexBuckets(Helper::readNumericValue<uint32_t>(
|
||||||
info, "indexBuckets", DatabaseFeature::defaultIndexBuckets())),
|
info, "indexBuckets", DatabaseFeature::defaultIndexBuckets())),
|
||||||
|
@ -209,8 +192,7 @@ LogicalCollection::LogicalCollection(TRI_vocbase_t* vocbase,
|
||||||
_vocbase(vocbase),
|
_vocbase(vocbase),
|
||||||
_cleanupIndexes(0),
|
_cleanupIndexes(0),
|
||||||
_persistentIndexes(0),
|
_persistentIndexes(0),
|
||||||
_physical(EngineSelectorFeature::ENGINE->createPhysicalCollection(this,info)),
|
_physical(EngineSelectorFeature::ENGINE->createPhysicalCollection(this,info)) {
|
||||||
_keyGenerator() {
|
|
||||||
getPhysical()->setPath(ReadStringValue(info, "path", ""));
|
getPhysical()->setPath(ReadStringValue(info, "path", ""));
|
||||||
if (!IsAllowedName(info)) {
|
if (!IsAllowedName(info)) {
|
||||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_ILLEGAL_NAME);
|
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_ILLEGAL_NAME);
|
||||||
|
@ -332,8 +314,6 @@ LogicalCollection::LogicalCollection(TRI_vocbase_t* vocbase,
|
||||||
"invalid number of shard keys");
|
"invalid number of shard keys");
|
||||||
}
|
}
|
||||||
|
|
||||||
_keyGenerator.reset(KeyGenerator::factory(info.get("keyOptions")));
|
|
||||||
|
|
||||||
auto shardsSlice = info.get("shards");
|
auto shardsSlice = info.get("shards");
|
||||||
if (shardsSlice.isObject()) {
|
if (shardsSlice.isObject()) {
|
||||||
for (auto const& shardSlice : VPackObjectIterator(shardsSlice)) {
|
for (auto const& shardSlice : VPackObjectIterator(shardsSlice)) {
|
||||||
|
@ -649,14 +629,6 @@ std::unique_ptr<FollowerInfo> const& LogicalCollection::followers() const {
|
||||||
|
|
||||||
void LogicalCollection::setDeleted(bool newValue) { _isDeleted = newValue; }
|
void LogicalCollection::setDeleted(bool newValue) { _isDeleted = newValue; }
|
||||||
|
|
||||||
// SECTION: Key Options
|
|
||||||
VPackSlice LogicalCollection::keyOptions() const {
|
|
||||||
if (_keyOptions == nullptr) {
|
|
||||||
return Helper::NullValue();
|
|
||||||
}
|
|
||||||
return VPackSlice(_keyOptions->data());
|
|
||||||
}
|
|
||||||
|
|
||||||
// SECTION: Indexes
|
// SECTION: Indexes
|
||||||
uint32_t LogicalCollection::indexBuckets() const { return _indexBuckets; }
|
uint32_t LogicalCollection::indexBuckets() const { return _indexBuckets; }
|
||||||
|
|
||||||
|
@ -691,7 +663,14 @@ void LogicalCollection::getPropertiesVPack(VPackBuilder& result, bool translateC
|
||||||
result.add("journalSize", VPackValue(getPhysical()->journalSize())); //MMFiles
|
result.add("journalSize", VPackValue(getPhysical()->journalSize())); //MMFiles
|
||||||
result.add("doCompact", VPackValue(getPhysical()->doCompact())); //MMFiles
|
result.add("doCompact", VPackValue(getPhysical()->doCompact())); //MMFiles
|
||||||
result.add("indexBuckets", VPackValue(_indexBuckets)); //MMFiles
|
result.add("indexBuckets", VPackValue(_indexBuckets)); //MMFiles
|
||||||
|
// MMFiles
|
||||||
|
if (getPhysical()->keyGenerator() != nullptr) {
|
||||||
|
result.add(VPackValue("keyOptions"));
|
||||||
|
result.openObject();
|
||||||
|
getPhysical()->keyGenerator()->toVelocyPack(result);
|
||||||
|
result.close();
|
||||||
|
}
|
||||||
|
|
||||||
result.add("replicationFactor", VPackValue(_replicationFactor));
|
result.add("replicationFactor", VPackValue(_replicationFactor));
|
||||||
if (!_distributeShardsLike.empty()) {
|
if (!_distributeShardsLike.empty()) {
|
||||||
if (translateCids) {
|
if (translateCids) {
|
||||||
|
@ -705,13 +684,6 @@ void LogicalCollection::getPropertiesVPack(VPackBuilder& result, bool translateC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_keyGenerator != nullptr) {
|
|
||||||
result.add(VPackValue("keyOptions"));
|
|
||||||
result.openObject();
|
|
||||||
_keyGenerator->toVelocyPack(result);
|
|
||||||
result.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
result.add(VPackValue("shardKeys"));
|
result.add(VPackValue("shardKeys"));
|
||||||
result.openArray();
|
result.openArray();
|
||||||
for (auto const& key : _shardKeys) {
|
for (auto const& key : _shardKeys) {
|
||||||
|
|
|
@ -54,7 +54,6 @@ struct DocumentIdentifierToken;
|
||||||
class FollowerInfo;
|
class FollowerInfo;
|
||||||
class Index;
|
class Index;
|
||||||
class IndexIterator;
|
class IndexIterator;
|
||||||
class KeyGenerator;
|
|
||||||
class ManagedDocumentResult;
|
class ManagedDocumentResult;
|
||||||
struct OperationOptions;
|
struct OperationOptions;
|
||||||
class PhysicalCollection;
|
class PhysicalCollection;
|
||||||
|
@ -171,15 +170,6 @@ class LogicalCollection {
|
||||||
|
|
||||||
void setDeleted(bool);
|
void setDeleted(bool);
|
||||||
|
|
||||||
// SECTION: Key Options
|
|
||||||
velocypack::Slice keyOptions() const;
|
|
||||||
|
|
||||||
// Get a reference to this KeyGenerator.
|
|
||||||
// Caller is not allowed to free it.
|
|
||||||
inline KeyGenerator* keyGenerator() const {
|
|
||||||
return _keyGenerator.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
PhysicalCollection* getPhysical() const { return _physical.get(); }
|
PhysicalCollection* getPhysical() const { return _physical.get(); }
|
||||||
|
|
||||||
std::unique_ptr<IndexIterator> getAllIterator(transaction::Methods* trx, ManagedDocumentResult* mdr, bool reverse);
|
std::unique_ptr<IndexIterator> getAllIterator(transaction::Methods* trx, ManagedDocumentResult* mdr, bool reverse);
|
||||||
|
@ -375,11 +365,6 @@ private:
|
||||||
bool const _isVolatile;
|
bool const _isVolatile;
|
||||||
bool _waitForSync;
|
bool _waitForSync;
|
||||||
|
|
||||||
// SECTION: Key Options
|
|
||||||
// TODO Really VPack?
|
|
||||||
std::shared_ptr<velocypack::Buffer<uint8_t> const>
|
|
||||||
_keyOptions; // options for key creation
|
|
||||||
|
|
||||||
uint32_t _version;
|
uint32_t _version;
|
||||||
|
|
||||||
// SECTION: Indexes
|
// SECTION: Indexes
|
||||||
|
@ -410,8 +395,6 @@ private:
|
||||||
|
|
||||||
std::unique_ptr<PhysicalCollection> _physical;
|
std::unique_ptr<PhysicalCollection> _physical;
|
||||||
|
|
||||||
std::unique_ptr<KeyGenerator> _keyGenerator;
|
|
||||||
|
|
||||||
mutable basics::ReadWriteLock
|
mutable basics::ReadWriteLock
|
||||||
_lock; // lock protecting the status and name
|
_lock; // lock protecting the status and name
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include "Basics/encoding.h"
|
#include "Basics/encoding.h"
|
||||||
#include "Basics/StaticStrings.h"
|
#include "Basics/StaticStrings.h"
|
||||||
|
#include "Basics/VelocyPackHelper.h"
|
||||||
#include "StorageEngine/TransactionState.h"
|
#include "StorageEngine/TransactionState.h"
|
||||||
#include "Transaction/Methods.h"
|
#include "Transaction/Methods.h"
|
||||||
#include "VocBase/KeyGenerator.h"
|
#include "VocBase/KeyGenerator.h"
|
||||||
|
@ -40,6 +41,17 @@
|
||||||
|
|
||||||
using namespace arangodb;
|
using namespace arangodb;
|
||||||
|
|
||||||
|
PhysicalCollection::PhysicalCollection(LogicalCollection* collection,
|
||||||
|
VPackSlice const& info)
|
||||||
|
: _logicalCollection(collection), _keyOptions(nullptr), _keyGenerator() {
|
||||||
|
TRI_ASSERT(info.isObject());
|
||||||
|
auto keyOpts = info.get("keyOptions");
|
||||||
|
|
||||||
|
_keyGenerator.reset(KeyGenerator::factory(keyOpts));
|
||||||
|
if (!keyOpts.isNone()) {
|
||||||
|
_keyOptions = VPackBuilder::clone(keyOpts).steal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PhysicalCollection::figures(std::shared_ptr<arangodb::velocypack::Builder>& builder){
|
void PhysicalCollection::figures(std::shared_ptr<arangodb::velocypack::Builder>& builder){
|
||||||
this->figuresSpecific(builder);
|
this->figuresSpecific(builder);
|
||||||
|
@ -192,8 +204,7 @@ int PhysicalCollection::newObjectForInsert(
|
||||||
if (s.isNone()) {
|
if (s.isNone()) {
|
||||||
TRI_ASSERT(!isRestore); // need key in case of restore
|
TRI_ASSERT(!isRestore); // need key in case of restore
|
||||||
newRev = TRI_HybridLogicalClock();
|
newRev = TRI_HybridLogicalClock();
|
||||||
std::string keyString =
|
std::string keyString = keyGenerator()->generate(TRI_NewTickServer());
|
||||||
_logicalCollection->keyGenerator()->generate(TRI_NewTickServer());
|
|
||||||
if (keyString.empty()) {
|
if (keyString.empty()) {
|
||||||
return TRI_ERROR_ARANGO_OUT_OF_KEYS;
|
return TRI_ERROR_ARANGO_OUT_OF_KEYS;
|
||||||
}
|
}
|
||||||
|
@ -204,8 +215,7 @@ int PhysicalCollection::newObjectForInsert(
|
||||||
return TRI_ERROR_ARANGO_DOCUMENT_KEY_BAD;
|
return TRI_ERROR_ARANGO_DOCUMENT_KEY_BAD;
|
||||||
} else {
|
} else {
|
||||||
std::string keyString = s.copyString();
|
std::string keyString = s.copyString();
|
||||||
int res =
|
int res = keyGenerator()->validate(keyString, isRestore);
|
||||||
_logicalCollection->keyGenerator()->validate(keyString, isRestore);
|
|
||||||
if (res != TRI_ERROR_NO_ERROR) {
|
if (res != TRI_ERROR_NO_ERROR) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -332,3 +342,11 @@ int PhysicalCollection::checkRevision(transaction::Methods* trx,
|
||||||
}
|
}
|
||||||
return TRI_ERROR_NO_ERROR;
|
return TRI_ERROR_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SECTION: Key Options
|
||||||
|
VPackSlice PhysicalCollection::keyOptions() const {
|
||||||
|
if (_keyOptions == nullptr) {
|
||||||
|
return arangodb::basics::VelocyPackHelper::NullValue();
|
||||||
|
}
|
||||||
|
return VPackSlice(_keyOptions->data());
|
||||||
|
}
|
||||||
|
|
|
@ -40,13 +40,15 @@ class Methods;
|
||||||
struct DocumentIdentifierToken;
|
struct DocumentIdentifierToken;
|
||||||
class Index;
|
class Index;
|
||||||
class IndexIterator;
|
class IndexIterator;
|
||||||
|
class KeyGenerator;
|
||||||
class LogicalCollection;
|
class LogicalCollection;
|
||||||
class ManagedDocumentResult;
|
class ManagedDocumentResult;
|
||||||
struct OperationOptions;
|
struct OperationOptions;
|
||||||
|
|
||||||
class PhysicalCollection {
|
class PhysicalCollection {
|
||||||
protected:
|
protected:
|
||||||
explicit PhysicalCollection(LogicalCollection* collection, VPackSlice const& info) : _logicalCollection(collection) {}
|
PhysicalCollection(LogicalCollection* collection,
|
||||||
|
arangodb::velocypack::Slice const& info);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~PhysicalCollection() = default;
|
virtual ~PhysicalCollection() = default;
|
||||||
|
@ -165,6 +167,16 @@ class PhysicalCollection {
|
||||||
TRI_voc_tick_t& resultMarkerTick, bool lock,
|
TRI_voc_tick_t& resultMarkerTick, bool lock,
|
||||||
TRI_voc_rid_t const& revisionId, TRI_voc_rid_t& prevRev) = 0;
|
TRI_voc_rid_t const& revisionId, TRI_voc_rid_t& prevRev) = 0;
|
||||||
|
|
||||||
|
// Get a reference to this KeyGenerator.
|
||||||
|
// Caller is not allowed to free it.
|
||||||
|
inline KeyGenerator* keyGenerator() const {
|
||||||
|
return _keyGenerator.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// SECTION: Key Options
|
||||||
|
velocypack::Slice keyOptions() const;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// SECTION: Document pre commit preperation
|
// SECTION: Document pre commit preperation
|
||||||
|
@ -206,6 +218,15 @@ class PhysicalCollection {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
LogicalCollection* _logicalCollection;
|
LogicalCollection* _logicalCollection;
|
||||||
|
|
||||||
|
// SECTION: Key Options
|
||||||
|
// TODO Really VPack?
|
||||||
|
std::shared_ptr<velocypack::Buffer<uint8_t> const>
|
||||||
|
_keyOptions; // options for key creation
|
||||||
|
|
||||||
|
|
||||||
|
std::unique_ptr<KeyGenerator> _keyGenerator;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace arangodb
|
} // namespace arangodb
|
||||||
|
|
Loading…
Reference in New Issue