Skip to content

Commit

Permalink
Make RocksDBStore.DeleteChainId() idempotent (#891)
Browse files Browse the repository at this point in the history
* Make RocksDBStore.DeleteChainId() idempotent

* Fix RocksDBStore's incorrect log context
  • Loading branch information
dahlia authored Jun 2, 2020
1 parent 9c38e2a commit 554692b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ Version 0.9.4

To be released.

- (Libplanet.RocksDBStore) Fixed a bug that `RocksDBStore.DeleteChainId()`
method had thrown `KeyNotFoundException` when there's no such chain ID.
[[#891]]
- (Libplanet.RocksDBStore) Fixed a bug that `RocksDBStore` had written logs
into the incorrect context `DefaultContext`, not `RocksDBStore`
the correct one. [[#891]]

[#891]: https://github.com/planetarium/libplanet/pull/891


Version 0.9.3
-------------
Expand Down
18 changes: 13 additions & 5 deletions Libplanet.RocksDBStore/RocksDBStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public RocksDBStore(
int statesCacheSize = 10000
)
{
_logger = Log.ForContext<DefaultStore>();
_logger = Log.ForContext<RocksDBStore>();

if (path is null)
{
Expand Down Expand Up @@ -141,11 +141,19 @@ public override IEnumerable<Guid> ListChainIds()
/// <inheritdoc/>
public override void DeleteChainId(Guid chainId)
{
_lastStateRefCaches.Remove(chainId);
try
{
_lastStateRefCaches.Remove(chainId);

var cfName = chainId.ToString();
_chainDb.DropColumnFamily(cfName);
_stateRefDb.DropColumnFamily(cfName);
var cfName = chainId.ToString();
_chainDb.DropColumnFamily(cfName);
_stateRefDb.DropColumnFamily(cfName);
}
catch (KeyNotFoundException)
{
// Do nothing according to the specification: DeleteChainId() should be idempotent.
_logger.Debug("No such chain ID: {ChainId}.", chainId);
}
}

/// <inheritdoc />
Expand Down
8 changes: 8 additions & 0 deletions Libplanet.Tests/Store/StoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public void DeleteChainId()
Assert.Equal(0, Fx.Store.GetTxNonce(Fx.StoreChainId, Fx.Transaction1.Signer));
}

[SkippableFact]
public void DeleteChainIdIsIdempotent()
{
Assert.Empty(Fx.Store.ListChainIds());
Fx.Store.DeleteChainId(Guid.NewGuid());
Assert.Empty(Fx.Store.ListChainIds());
}

[SkippableFact]
public void CanonicalChainId()
{
Expand Down

0 comments on commit 554692b

Please sign in to comment.