Skip to content

Commit

Permalink
fix doc and test around epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
ban-nobuhiro committed Feb 24, 2024
1 parent 4cf3574 commit b74e147
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/datastore-if.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
* この操作は `ready()` が呼び出される前に行う必要がある
* `datastore::last_epoch() -> epoch_id_type`
* overview
* 永続化に成功した最大の epoch ID を返す
* 永続化データ中に含まれる最大の epoch ID 以上の値を返す
* note
* この操作は、 `datastore::ready()` の実行前後のいずれでも利用可能 (`LOG-0` を除く)
* impl
Expand Down
21 changes: 12 additions & 9 deletions test/limestone/api/datastore_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class datastore_test : public ::testing::Test {

static void set_durable_epoch(std::size_t n) {
durable_epoch_.store(n, std::memory_order_release);
VLOG(30) << "set_durable_epoch " << n;
}

protected:
Expand All @@ -59,17 +60,19 @@ TEST_F(datastore_test, add_persistent_callback_test) { // NOLINT
// register persistent callback
datastore_->add_persistent_callback(set_durable_epoch);

// epoch 1
datastore_->switch_epoch(1);

// ready
datastore_->ready();

// epoch 2
datastore_->switch_epoch(2);
auto initial_epoch = datastore_->last_epoch(); // after ready()

VLOG(30) << "epoch 1";
datastore_->switch_epoch(initial_epoch + 1); // this will trigger no durable callbacks

VLOG(30) << "epoch 2";
datastore_->switch_epoch(initial_epoch + 2);

for (;;) {
if (get_durable_epoch() >= 1) {
if (get_durable_epoch() >= initial_epoch + 1) {
break;
}
_mm_pause();
Expand All @@ -80,11 +83,11 @@ TEST_F(datastore_test, add_persistent_callback_test) { // NOLINT
#endif
}

// epoch 3
datastore_->switch_epoch(3);
VLOG(30) << "epoch 3";
datastore_->switch_epoch(initial_epoch + 3);

for (;;) {
if (get_durable_epoch() >= 2) {
if (get_durable_epoch() >= initial_epoch + 2) {
break;
}
_mm_pause();
Expand Down

0 comments on commit b74e147

Please sign in to comment.