neo icon indicating copy to clipboard operation
neo copied to clipboard

[Neo Store UT] Add leveldb thread UT and readme.

Open Jim8y opened this issue 1 year ago • 7 comments

Description

Leveldb itself is not thread safe, thus having this pr to demonstrate how leveldb snapshot behaves under multi thread env.

Quote from leveldb document https://github.com/google/leveldb/blob/main/doc/index.md :

A database may only be opened by one process at a time. The leveldb implementation acquires a lock from the operating system to prevent misuse. Within a single process, the same leveldb::DB object may be safely shared by multiple concurrent threads. I.e., different threads may write into or fetch iterators or call Get on the same database without any external synchronization (the leveldb implementation will automatically do the required synchronization). However other objects (like Iterator and WriteBatch) may require external synchronization. If two threads share such an object, they must protect access to it using their own locking protocol. More details are available in the public header files.

Fixes # (issue)

Type of change

  • [ ] Optimization (the change is only an optimization)
  • [x] Style (the change is only a code style for better maintenance or standard purpose)
  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] This change requires a documentation update

How Has This Been Tested?

  • [x] TestMultiThreadLevelDbSnapshotPut
  • [x] TestMultiThreadLevelDbSnapshotPutWithoutCommit
  • [x] TestMultiThreadLevelDbSnapshotPutWithLocker
  • [x] TestOneSnapshotPerThreadLevelDbSnapshotPut

Test Configuration:

Checklist:

  • [x] My code follows the style guidelines of this project
  • [x] I have performed a self-review of my code
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [x] My changes generate no new warnings
  • [x] I have added tests that prove my fix is effective or that my feature works
  • [x] New and existing unit tests pass locally with my changes
  • [x] Any dependent changes have been merged and published in downstream modules

Jim8y avatar Jul 18 '24 17:07 Jim8y

But leveldb does support multi-threading and so does the interface (IStore). The classes that inherit IStore are not thread safe. I said this at the begin when i started work here.

No, it does not. Did i do anything saying it does here? Aren't we are saying exactly the same thing?

Jim8y avatar Jul 18 '24 17:07 Jim8y

Then why you think your tests are failing than? Your testing the wrong thing, you need to be testing SnapshotCache and DataCache

cschuchardt88 avatar Jul 18 '24 17:07 cschuchardt88

Then why you think your tests are failing than? Your testing the wrong thing, you need to be testing SnapshotCache and DataCache

which test are failing, aren't they all passed? Will test snapshotcache later.

Jim8y avatar Jul 18 '24 17:07 Jim8y

Then why you think your tests are failing than? Your testing the wrong thing, you need to be testing SnapshotCache and DataCache

which test are failing, aren't they all passed? Will test snapshotcache later.

image

cschuchardt88 avatar Jul 18 '24 18:07 cschuchardt88

Then why you think your tests are failing than? Your testing the wrong thing, you need to be testing SnapshotCache and DataCache

which test are failing, aren't they all passed? Will test snapshotcache later.

image

Will update.

Jim8y avatar Jul 19 '24 01:07 Jim8y

one UT is faulted :S

shargon avatar Sep 11 '24 07:09 shargon

@Jim8y one test fail

shargon avatar Sep 28 '24 09:09 shargon

@Jim8y this has been fixed already. close?

cschuchardt88 avatar Dec 09 '24 09:12 cschuchardt88

fixed

Jim8y avatar Dec 09 '24 10:12 Jim8y