Fix timestamps saving on-disk (#1811)
This commit is contained in:
parent
0913e95167
commit
a3d2474c5b
@ -42,7 +42,7 @@ DurableMetadata::DurableMetadata(const Config &config)
|
||||
DurableMetadata::DurableMetadata(DurableMetadata &&other) noexcept
|
||||
: durability_kvstore_(std::move(other.durability_kvstore_)), config_(std::move(other.config_)) {}
|
||||
|
||||
void DurableMetadata::SaveBeforeClosingDB(uint64_t timestamp, uint64_t vertex_count, uint64_t edge_count) {
|
||||
void DurableMetadata::UpdateMetaData(uint64_t timestamp, uint64_t vertex_count, uint64_t edge_count) {
|
||||
durability_kvstore_.Put(kLastTransactionStartTimeStamp, std::to_string(timestamp));
|
||||
durability_kvstore_.Put(kVertexCountDescr, std::to_string(vertex_count));
|
||||
durability_kvstore_.Put(kEdgeDountDescr, std::to_string(edge_count));
|
||||
|
@ -41,7 +41,7 @@ class DurableMetadata {
|
||||
std::optional<std::vector<std::string>> LoadExistenceConstraintInfoIfExists() const;
|
||||
std::optional<std::vector<std::string>> LoadUniqueConstraintInfoIfExists() const;
|
||||
|
||||
void SaveBeforeClosingDB(uint64_t timestamp, uint64_t vertex_count, uint64_t edge_count);
|
||||
void UpdateMetaData(uint64_t timestamp, uint64_t vertex_count, uint64_t edge_count);
|
||||
|
||||
bool PersistLabelIndexCreation(LabelId label);
|
||||
|
||||
|
@ -274,8 +274,8 @@ DiskStorage::DiskStorage(Config config)
|
||||
}
|
||||
|
||||
DiskStorage::~DiskStorage() {
|
||||
durable_metadata_.SaveBeforeClosingDB(timestamp_, vertex_count_.load(std::memory_order_acquire),
|
||||
edge_count_.load(std::memory_order_acquire));
|
||||
durable_metadata_.UpdateMetaData(timestamp_, vertex_count_.load(std::memory_order_acquire),
|
||||
edge_count_.load(std::memory_order_acquire));
|
||||
logging::AssertRocksDBStatus(kvstore_->db_->DestroyColumnFamilyHandle(kvstore_->vertex_chandle));
|
||||
logging::AssertRocksDBStatus(kvstore_->db_->DestroyColumnFamilyHandle(kvstore_->edge_chandle));
|
||||
logging::AssertRocksDBStatus(kvstore_->db_->DestroyColumnFamilyHandle(kvstore_->out_edges_chandle));
|
||||
@ -1786,7 +1786,8 @@ utils::BasicResult<StorageManipulationError, void> DiskStorage::DiskAccessor::Co
|
||||
if (flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
|
||||
disk_storage->indices_.text_index_.Commit();
|
||||
}
|
||||
|
||||
disk_storage->durable_metadata_.UpdateMetaData(disk_storage->timestamp_, disk_storage->vertex_count_,
|
||||
disk_storage->edge_count_);
|
||||
is_transaction_active_ = false;
|
||||
|
||||
return {};
|
||||
|
@ -301,6 +301,8 @@ class DiskStorage final : public Storage {
|
||||
|
||||
EdgeImportMode GetEdgeImportMode() const;
|
||||
|
||||
DurableMetadata *GetDurableMetadata() { return &durable_metadata_; }
|
||||
|
||||
private:
|
||||
void LoadPersistingMetadataInfo();
|
||||
|
||||
|
@ -179,3 +179,35 @@ TEST_F(ClearingOldDiskDataTest, TestNumOfEntriesWithEdgeValueUpdate) {
|
||||
|
||||
ASSERT_EQ(disk_test_utils::GetRealNumberOfEntriesInRocksDB(tx_db), 5);
|
||||
}
|
||||
|
||||
TEST_F(ClearingOldDiskDataTest, TestTimestampAfterCommit) {
|
||||
auto *tx_db = disk_storage->GetRocksDBStorage()->db_;
|
||||
ASSERT_EQ(disk_test_utils::GetRealNumberOfEntriesInRocksDB(tx_db), 0);
|
||||
|
||||
auto acc1 = disk_storage->Access(ReplicationRole::MAIN);
|
||||
auto vertex1 = acc1->CreateVertex();
|
||||
auto label1 = acc1->NameToLabel("DiskLabel");
|
||||
auto property1 = acc1->NameToProperty("DiskProperty");
|
||||
ASSERT_TRUE(vertex1.AddLabel(label1).HasValue());
|
||||
ASSERT_TRUE(vertex1.SetProperty(property1, memgraph::storage::PropertyValue(10)).HasValue());
|
||||
ASSERT_FALSE(acc1->Commit().HasError());
|
||||
ASSERT_EQ(disk_test_utils::GetRealNumberOfEntriesInRocksDB(tx_db), 1);
|
||||
|
||||
auto saved_timestamp = disk_storage->GetDurableMetadata()->LoadTimestampIfExists();
|
||||
ASSERT_EQ(saved_timestamp.has_value(), true);
|
||||
ASSERT_EQ(disk_storage->timestamp_, saved_timestamp);
|
||||
|
||||
auto acc2 = disk_storage->Access(ReplicationRole::MAIN);
|
||||
auto vertex2 = acc2->CreateVertex();
|
||||
auto label2 = acc2->NameToLabel("DiskLabel2");
|
||||
auto property2 = acc2->NameToProperty("DiskProperty2");
|
||||
|
||||
ASSERT_TRUE(vertex2.AddLabel(label2).HasValue());
|
||||
ASSERT_TRUE(vertex2.SetProperty(property2, memgraph::storage::PropertyValue(10)).HasValue());
|
||||
ASSERT_FALSE(acc2->Commit().HasError());
|
||||
ASSERT_EQ(disk_test_utils::GetRealNumberOfEntriesInRocksDB(tx_db), 2);
|
||||
|
||||
saved_timestamp = disk_storage->GetDurableMetadata()->LoadTimestampIfExists();
|
||||
ASSERT_EQ(saved_timestamp.has_value(), true);
|
||||
ASSERT_EQ(disk_storage->timestamp_, saved_timestamp);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user