Skip to content

Commit

Permalink
storage/mkvs: Don't try to sync dirty keys
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Mar 23, 2020
1 parent ee1d9fc commit e6de6fd
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions .changelog/2775.bugfix.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
storage/mkvs: Don't try to sync dirty keys
7 changes: 7 additions & 0 deletions go/storage/mkvs/urkel/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ func (t *tree) Get(ctx context.Context, key []byte) ([]byte, error) {
return nil, ErrClosed
}

// If the key has been modified locally, no need to perform any lookups.
if !t.withoutWriteLog {
if entry := t.pendingWriteLog[node.ToMapKey(key)]; entry != nil {
return entry.value, nil
}
}

// Remember where the path from root to target node ends (will end).
t.cache.markPosition()

Expand Down
9 changes: 8 additions & 1 deletion go/storage/mkvs/urkel/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ func (t *tree) RemoveExisting(ctx context.Context, key []byte) ([]byte, error) {
return nil, ErrClosed
}

// If the key has already been removed locally, don't try to remove it again.
var entry *pendingEntry
if !t.withoutWriteLog {
if entry = t.pendingWriteLog[node.ToMapKey(key)]; entry != nil && entry.value == nil {
return nil, nil
}
}

// Remember where the path from root to target node ends (will end).
t.cache.markPosition()

Expand All @@ -26,7 +34,6 @@ func (t *tree) RemoveExisting(ctx context.Context, key []byte) ([]byte, error) {

// Update the pending write log.
if !t.withoutWriteLog {
entry := t.pendingWriteLog[node.ToMapKey(key)]
if entry == nil {
t.pendingWriteLog[node.ToMapKey(key)] = &pendingEntry{key, nil, changed, nil}
} else {
Expand Down
18 changes: 18 additions & 0 deletions go/storage/mkvs/urkel/testdata/case-5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"op": "Insert",
"key": "AwAA"
},
{
"op": "Insert",
"key": "AwAe"
},
{
"op": "Insert",
"key": "AAAe"
},
{
"op": "Remove",
"key": "AAAe"
}
]
5 changes: 5 additions & 0 deletions go/storage/mkvs/urkel/urkel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1872,6 +1872,10 @@ func testSpecialCase4(t *testing.T, ndb db.NodeDB, factory NodeDBFactory) {
testSpecialCaseFromJSON(t, ndb, "case-4.json")
}

func testSpecialCase5(t *testing.T, ndb db.NodeDB, factory NodeDBFactory) {
testSpecialCaseFromJSON(t, ndb, "case-5.json")
}

func testBackend(
t *testing.T,
initBackend func(t *testing.T) (NodeDBFactory, func()),
Expand Down Expand Up @@ -1911,6 +1915,7 @@ func testBackend(
{"SpecialCase2", testSpecialCase2},
{"SpecialCase3", testSpecialCase3},
{"SpecialCase4", testSpecialCase4},
{"SpecialCase5", testSpecialCase5},
{"Errors", testErrors},
}

Expand Down
5 changes: 5 additions & 0 deletions runtime/src/storage/mkvs/urkel/tree/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ impl UrkelTree {
let boxed_key = key.to_vec();
let pending_root = self.cache.borrow().get_pending_root();

// If the key has been modified locally, no need to perform any lookups.
if let Some(PendingLogEntry { ref value, .. }) = self.pending_write_log.get(&boxed_key) {
return Ok(value.clone());
}

// Remember where the path from root to target node ends (will end).
self.cache.borrow_mut().mark_position();

Expand Down
5 changes: 5 additions & 0 deletions runtime/src/storage/mkvs/urkel/tree/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ impl UrkelTree {
let boxed_key = key.to_vec();
let pending_root = self.cache.borrow().get_pending_root();

// If the key has already been removed locally, don't try to remove it again.
if let Some(PendingLogEntry { value: None, .. }) = self.pending_write_log.get(&boxed_key) {
return Ok(None);
}

// Remember where the path from root to target node ends (will end).
self.cache.borrow_mut().mark_position();

Expand Down

0 comments on commit e6de6fd

Please sign in to comment.