Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RocksDBStore.DeleteChainId() idempotent #891

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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