mirror of https://gitee.com/bigwinds/arangodb
add buffer() to RocksDBValue for data retrieval
This commit is contained in:
parent
c038815941
commit
772a7a32da
|
@ -105,7 +105,7 @@ arangodb::Result RocksDBCollection::persistProperties() {
|
||||||
|
|
||||||
RocksDBKey key(RocksDBKey::Collection(_logicalCollection->vocbase()->id(), _objectId));
|
RocksDBKey key(RocksDBKey::Collection(_logicalCollection->vocbase()->id(), _objectId));
|
||||||
RocksDBValue value(RocksDBValue::Document(infoBuilder.slice()));
|
RocksDBValue value(RocksDBValue::Document(infoBuilder.slice()));
|
||||||
res = globalRocksDBPut(key.string(), *value.string());
|
res = globalRocksDBPut(key.string(), value.string());
|
||||||
|
|
||||||
} catch (arangodb::basics::Exception const& ex) {
|
} catch (arangodb::basics::Exception const& ex) {
|
||||||
res.reset(ex.code());
|
res.reset(ex.code());
|
||||||
|
@ -810,7 +810,7 @@ int RocksDBCollection::insertDocument(arangodb::transaction::Methods* trx,
|
||||||
<< "INSERT DOCUMENT. COLLECTION '" << _logicalCollection->name()
|
<< "INSERT DOCUMENT. COLLECTION '" << _logicalCollection->name()
|
||||||
<< "', OBJECTID: " << _objectId << ", REVISIONID: " << revisionId;
|
<< "', OBJECTID: " << _objectId << ", REVISIONID: " << revisionId;
|
||||||
|
|
||||||
rocksdb::Status status = rtrx->Put(key.string(), *value.string());
|
rocksdb::Status status = rtrx->Put(key.string(), value.string());
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
auto converted =
|
auto converted =
|
||||||
rocksutils::convertStatus(status, rocksutils::StatusHint::document);
|
rocksutils::convertStatus(status, rocksutils::StatusHint::document);
|
||||||
|
|
|
@ -245,14 +245,14 @@ void RocksDBEngine::getCollectionInfo(TRI_vocbase_t* vocbase, TRI_voc_cid_t cid,
|
||||||
auto key = RocksDBKey::Collection(vocbase->id(), cid);
|
auto key = RocksDBKey::Collection(vocbase->id(), cid);
|
||||||
auto value = RocksDBValue::Empty(RocksDBEntryType::Collection);
|
auto value = RocksDBValue::Empty(RocksDBEntryType::Collection);
|
||||||
rocksdb::ReadOptions options;
|
rocksdb::ReadOptions options;
|
||||||
rocksdb::Status res = _db->Get(options, key.string(), value.string());
|
rocksdb::Status res = _db->Get(options, key.string(), value.buffer());
|
||||||
auto result = rocksutils::convertStatus(res);
|
auto result = rocksutils::convertStatus(res);
|
||||||
|
|
||||||
if (result.errorNumber() != TRI_ERROR_NO_ERROR) {
|
if (result.errorNumber() != TRI_ERROR_NO_ERROR) {
|
||||||
THROW_ARANGO_EXCEPTION(result.errorNumber());
|
THROW_ARANGO_EXCEPTION(result.errorNumber());
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.add("parameters", VPackSlice(value.string()->data()));
|
builder.add("parameters", VPackSlice(value.buffer()->data()));
|
||||||
|
|
||||||
if (includeIndexes) {
|
if (includeIndexes) {
|
||||||
// dump index information
|
// dump index information
|
||||||
|
@ -386,7 +386,7 @@ int RocksDBEngine::writeCreateDatabaseMarker(TRI_voc_tick_t id,
|
||||||
auto value = RocksDBValue::Database(slice);
|
auto value = RocksDBValue::Database(slice);
|
||||||
rocksdb::WriteOptions options; // TODO: check which options would make sense
|
rocksdb::WriteOptions options; // TODO: check which options would make sense
|
||||||
|
|
||||||
rocksdb::Status res = _db->Put(options, key.string(), *value.string());
|
rocksdb::Status res = _db->Put(options, key.string(), value.string());
|
||||||
auto result = rocksutils::convertStatus(res);
|
auto result = rocksutils::convertStatus(res);
|
||||||
return result.errorNumber();
|
return result.errorNumber();
|
||||||
}
|
}
|
||||||
|
@ -398,7 +398,7 @@ int RocksDBEngine::writeCreateCollectionMarker(TRI_voc_tick_t databaseId,
|
||||||
auto value = RocksDBValue::Collection(slice);
|
auto value = RocksDBValue::Collection(slice);
|
||||||
rocksdb::WriteOptions options; // TODO: check which options would make sense
|
rocksdb::WriteOptions options; // TODO: check which options would make sense
|
||||||
|
|
||||||
rocksdb::Status res = _db->Put(options, key.string(), *value.string());
|
rocksdb::Status res = _db->Put(options, key.string(), value.string());
|
||||||
auto result = rocksutils::convertStatus(res);
|
auto result = rocksutils::convertStatus(res);
|
||||||
return result.errorNumber();
|
return result.errorNumber();
|
||||||
}
|
}
|
||||||
|
@ -499,7 +499,7 @@ void RocksDBEngine::createIndex(TRI_vocbase_t* vocbase,
|
||||||
auto key = RocksDBKey::Index(vocbase->id(), collectionId, indexId);
|
auto key = RocksDBKey::Index(vocbase->id(), collectionId, indexId);
|
||||||
auto value = RocksDBValue::Index(data);
|
auto value = RocksDBValue::Index(data);
|
||||||
|
|
||||||
rocksdb::Status res = _db->Put(options, key.string(), *value.string());
|
rocksdb::Status res = _db->Put(options, key.string(), value.string());
|
||||||
auto result = rocksutils::convertStatus(res);
|
auto result = rocksutils::convertStatus(res);
|
||||||
if (!result.ok()) {
|
if (!result.ok()) {
|
||||||
THROW_ARANGO_EXCEPTION(result.errorNumber());
|
THROW_ARANGO_EXCEPTION(result.errorNumber());
|
||||||
|
|
|
@ -216,7 +216,8 @@ RocksDBToken RocksDBPrimaryIndex::lookupKey(transaction::Methods* trx,
|
||||||
auto f = _cache->find(key.string().data(),
|
auto f = _cache->find(key.string().data(),
|
||||||
static_cast<uint32_t>(key.string().size()));
|
static_cast<uint32_t>(key.string().size()));
|
||||||
if (f.found()) {
|
if (f.found()) {
|
||||||
value.string()->append(reinterpret_cast<char const*>(f.value()->value()),
|
f.value();
|
||||||
|
value.buffer()->append(reinterpret_cast<char const*>(f.value()->value()),
|
||||||
static_cast<size_t>(f.value()->valueSize));
|
static_cast<size_t>(f.value()->valueSize));
|
||||||
return RocksDBToken(RocksDBValue::revisionId(value));
|
return RocksDBToken(RocksDBValue::revisionId(value));
|
||||||
}
|
}
|
||||||
|
@ -227,7 +228,7 @@ RocksDBToken RocksDBPrimaryIndex::lookupKey(transaction::Methods* trx,
|
||||||
rocksdb::Transaction* rtrx = state->rocksTransaction();
|
rocksdb::Transaction* rtrx = state->rocksTransaction();
|
||||||
auto options = state->readOptions();
|
auto options = state->readOptions();
|
||||||
|
|
||||||
auto status = rtrx->Get(options, key.string(), value.string());
|
auto status = rtrx->Get(options, key.string(), value.buffer());
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
return RocksDBToken();
|
return RocksDBToken();
|
||||||
}
|
}
|
||||||
|
@ -236,7 +237,7 @@ RocksDBToken RocksDBPrimaryIndex::lookupKey(transaction::Methods* trx,
|
||||||
// write entry back to cache
|
// write entry back to cache
|
||||||
auto entry = cache::CachedValue::construct(
|
auto entry = cache::CachedValue::construct(
|
||||||
key.string().data(), static_cast<uint32_t>(key.string().size()),
|
key.string().data(), static_cast<uint32_t>(key.string().size()),
|
||||||
value.string()->data(), static_cast<uint64_t>(value.string()->size()));
|
value.buffer()->data(), static_cast<uint64_t>(value.buffer()->size()));
|
||||||
bool cached = _cache->insert(entry);
|
bool cached = _cache->insert(entry);
|
||||||
if (!cached) {
|
if (!cached) {
|
||||||
delete entry;
|
delete entry;
|
||||||
|
@ -257,7 +258,7 @@ RocksDBToken RocksDBPrimaryIndex::lookupKey(
|
||||||
rocksdb::Transaction* rtrx = state->rocksTransaction();
|
rocksdb::Transaction* rtrx = state->rocksTransaction();
|
||||||
auto options = state->readOptions();
|
auto options = state->readOptions();
|
||||||
|
|
||||||
auto status = rtrx->Get(options, key.string(), value.string());
|
auto status = rtrx->Get(options, key.string(), value.buffer());
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
return RocksDBToken();
|
return RocksDBToken();
|
||||||
}
|
}
|
||||||
|
@ -291,7 +292,7 @@ int RocksDBPrimaryIndex::insert(transaction::Methods* trx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto status = rtrx->Put(key.string(), *value.string());
|
auto status = rtrx->Put(key.string(), value.string());
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
auto converted =
|
auto converted =
|
||||||
rocksutils::convertStatus(status, rocksutils::StatusHint::index);
|
rocksutils::convertStatus(status, rocksutils::StatusHint::index);
|
||||||
|
|
|
@ -503,14 +503,14 @@ int RocksDBVPackIndex::insert(transaction::Methods* trx,
|
||||||
if (_unique) {
|
if (_unique) {
|
||||||
RocksDBValue existing =
|
RocksDBValue existing =
|
||||||
RocksDBValue::Empty(RocksDBEntryType::UniqueIndexValue);
|
RocksDBValue::Empty(RocksDBEntryType::UniqueIndexValue);
|
||||||
auto status = rtrx->Get(options, key.string(), existing.string());
|
auto status = rtrx->Get(options, key.string(), existing.buffer());
|
||||||
if (!status.IsNotFound()) {
|
if (!status.IsNotFound()) {
|
||||||
res = TRI_ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED;
|
res = TRI_ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res == TRI_ERROR_NO_ERROR) {
|
if (res == TRI_ERROR_NO_ERROR) {
|
||||||
auto s = rtrx->Put(key.string(), *value.string());
|
auto s = rtrx->Put(key.string(), value.string());
|
||||||
|
|
||||||
auto status = rocksutils::convertStatus(s, rocksutils::StatusHint::index);
|
auto status = rocksutils::convertStatus(s, rocksutils::StatusHint::index);
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
|
|
|
@ -105,8 +105,6 @@ VPackSlice RocksDBValue::data(std::string const& s) {
|
||||||
return data(s.data(), s.size());
|
return data(s.data(), s.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string* RocksDBValue::string() { return &_buffer; }
|
|
||||||
|
|
||||||
RocksDBValue::RocksDBValue(RocksDBEntryType type) : _type(type), _buffer() {}
|
RocksDBValue::RocksDBValue(RocksDBEntryType type) : _type(type), _buffer() {}
|
||||||
|
|
||||||
RocksDBValue::RocksDBValue(RocksDBEntryType type, uint64_t data)
|
RocksDBValue::RocksDBValue(RocksDBEntryType type, uint64_t data)
|
||||||
|
|
|
@ -94,7 +94,8 @@ class RocksDBValue {
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief Returns a reference to the underlying string buffer.
|
/// @brief Returns a reference to the underlying string buffer.
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
std::string* string();
|
std::string const& string() { return _buffer; } // to be used with put
|
||||||
|
std::string* buffer() { return &_buffer; } // to be used with get
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RocksDBValue();
|
RocksDBValue();
|
||||||
|
|
Loading…
Reference in New Issue