mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-02-03 08:34:37 +00:00
wip: memory cache specific behavior
This commit is contained in:
parent
65a471802d
commit
8740b65a79
@ -39,9 +39,9 @@ type
|
||||
InvalidBlockSize* = object of CodexError
|
||||
|
||||
const
|
||||
MiB* = 1024 * 1024 # bytes, 1 mebibyte = 1,048,576 bytes
|
||||
MiB* = 1024 * 1024
|
||||
DefaultCacheSizeMiB* = 5
|
||||
DefaultCacheSize* = DefaultCacheSizeMiB * MiB # bytes
|
||||
DefaultCacheSize* = DefaultCacheSizeMiB * MiB
|
||||
|
||||
method getBlock*(self: MemoryStore, cid: Cid): Future[?!Block] {.async.} =
|
||||
trace "Getting block from cache", cid
|
||||
@ -163,8 +163,8 @@ method close*(self: MemoryStore): Future[void] {.async.} =
|
||||
func new*(
|
||||
_: type MemoryStore,
|
||||
blocks: openArray[Block] = [],
|
||||
capacity: Positive = DefaultCacheSize, # in bytes
|
||||
chunkSize: Positive = DefaultChunkSize # in bytes
|
||||
capacity: Positive = DefaultCacheSize,
|
||||
chunkSize: Positive = DefaultChunkSize
|
||||
): MemoryStore {.raises: [Defect, ValueError].} =
|
||||
if capacity < chunkSize:
|
||||
raise newException(ValueError, "capacity cannot be less than chunkSize")
|
||||
@ -174,7 +174,7 @@ func new*(
|
||||
bytesUsed: 0,
|
||||
capacity: capacity)
|
||||
|
||||
# for blk in blocks:
|
||||
# discard store.putBlockSync(blk)
|
||||
for blk in blocks:
|
||||
discard store.putBlockSync(blk)
|
||||
|
||||
return store
|
||||
|
@ -33,7 +33,7 @@ suite "Block Advertising and Discovery":
|
||||
discovery: DiscoveryEngine
|
||||
wallet: WalletRef
|
||||
network: BlockExcNetwork
|
||||
localStore: CacheStore
|
||||
localStore: MemoryStore
|
||||
engine: BlockExcEngine
|
||||
pendingBlocks: PendingBlocksManager
|
||||
|
||||
@ -49,7 +49,7 @@ suite "Block Advertising and Discovery":
|
||||
blockDiscovery = MockDiscovery.new()
|
||||
wallet = WalletRef.example
|
||||
network = BlockExcNetwork.new(switch)
|
||||
localStore = CacheStore.new(blocks.mapIt( it ))
|
||||
localStore = MemoryStore.new(blocks.mapIt( it ))
|
||||
peerStore = PeerCtxStore.new()
|
||||
pendingBlocks = PendingBlocksManager.new()
|
||||
|
||||
|
@ -46,7 +46,7 @@ suite "Test Discovery Engine":
|
||||
|
||||
test "Should Query Wants":
|
||||
var
|
||||
localStore = CacheStore.new()
|
||||
localStore = MemoryStore.new()
|
||||
discoveryEngine = DiscoveryEngine.new(
|
||||
localStore,
|
||||
peerStore,
|
||||
@ -66,7 +66,7 @@ suite "Test Discovery Engine":
|
||||
|
||||
test "Should Advertise Haves":
|
||||
var
|
||||
localStore = CacheStore.new(blocks.mapIt( it ))
|
||||
localStore = MemoryStore.new(blocks.mapIt( it ))
|
||||
discoveryEngine = DiscoveryEngine.new(
|
||||
localStore,
|
||||
peerStore,
|
||||
@ -90,7 +90,7 @@ suite "Test Discovery Engine":
|
||||
|
||||
test "Should queue discovery request":
|
||||
var
|
||||
localStore = CacheStore.new()
|
||||
localStore = MemoryStore.new()
|
||||
discoveryEngine = DiscoveryEngine.new(
|
||||
localStore,
|
||||
peerStore,
|
||||
@ -113,7 +113,7 @@ suite "Test Discovery Engine":
|
||||
|
||||
test "Should queue advertise request":
|
||||
var
|
||||
localStore = CacheStore.new(@[blocks[0]])
|
||||
localStore = MemoryStore.new(@[blocks[0]])
|
||||
discoveryEngine = DiscoveryEngine.new(
|
||||
localStore,
|
||||
peerStore,
|
||||
@ -135,7 +135,7 @@ suite "Test Discovery Engine":
|
||||
|
||||
test "Should not request more than minPeersPerBlock":
|
||||
var
|
||||
localStore = CacheStore.new()
|
||||
localStore = MemoryStore.new()
|
||||
minPeers = 2
|
||||
discoveryEngine = DiscoveryEngine.new(
|
||||
localStore,
|
||||
@ -170,7 +170,7 @@ suite "Test Discovery Engine":
|
||||
|
||||
test "Should not request if there is already an inflight discovery request":
|
||||
var
|
||||
localStore = CacheStore.new()
|
||||
localStore = MemoryStore.new()
|
||||
discoveryEngine = DiscoveryEngine.new(
|
||||
localStore,
|
||||
peerStore,
|
||||
@ -204,7 +204,7 @@ suite "Test Discovery Engine":
|
||||
|
||||
test "Should not request if there is already an inflight advertise request":
|
||||
var
|
||||
localStore = CacheStore.new()
|
||||
localStore = MemoryStore.new()
|
||||
discoveryEngine = DiscoveryEngine.new(
|
||||
localStore,
|
||||
peerStore,
|
||||
|
@ -69,7 +69,7 @@ suite "NetworkStore engine basic":
|
||||
sendWantList: sendWantList,
|
||||
))
|
||||
|
||||
localStore = CacheStore.new(blocks.mapIt( it ))
|
||||
localStore = MemoryStore.new(blocks.mapIt( it ))
|
||||
discovery = DiscoveryEngine.new(
|
||||
localStore,
|
||||
peerStore,
|
||||
|
@ -48,7 +48,7 @@ suite "Storage Proofs Network":
|
||||
|
||||
setupAll:
|
||||
chunker = RandomChunker.new(Rng.instance(), size = DataSetSize, chunkSize = BlockSize)
|
||||
store = CacheStore.new(cacheSize = DataSetSize, chunkSize = BlockSize)
|
||||
store = MemoryStore.new(capacity = DataSetSize, chunkSize = BlockSize)
|
||||
manifest = Manifest.new(blockSize = BlockSize).tryGet()
|
||||
(spk, ssk) = st.keyGen()
|
||||
|
||||
|
@ -29,7 +29,7 @@ suite "BLS PoR":
|
||||
|
||||
setup:
|
||||
chunker = RandomChunker.new(Rng.instance(), size = DataSetSize, chunkSize = BlockSize)
|
||||
store = CacheStore.new(cacheSize = DataSetSize, chunkSize = BlockSize)
|
||||
store = MemoryStore.new(capacity = DataSetSize, chunkSize = BlockSize)
|
||||
manifest = Manifest.new(blockSize = BlockSize).tryGet()
|
||||
(spk, ssk) = st.keyGen()
|
||||
|
||||
@ -88,7 +88,7 @@ suite "Test Serialization":
|
||||
|
||||
setupAll:
|
||||
chunker = RandomChunker.new(Rng.instance(), size = DataSetSize, chunkSize = BlockSize)
|
||||
store = CacheStore.new(cacheSize = DataSetSize, chunkSize = BlockSize)
|
||||
store = MemoryStore.new(capacity = DataSetSize, chunkSize = BlockSize)
|
||||
manifest = Manifest.new(blockSize = BlockSize).tryGet()
|
||||
|
||||
while (
|
||||
|
@ -34,7 +34,7 @@ suite "Test PoR store":
|
||||
|
||||
setupAll:
|
||||
chunker = RandomChunker.new(Rng.instance(), size = DataSetSize, chunkSize = BlockSize)
|
||||
store = CacheStore.new(cacheSize = DataSetSize, chunkSize = BlockSize)
|
||||
store = MemoryStore.new(capacity = DataSetSize, chunkSize = BlockSize)
|
||||
manifest = Manifest.new(blockSize = BlockSize).tryGet()
|
||||
(spk, ssk) = st.keyGen()
|
||||
|
||||
|
@ -28,7 +28,7 @@ suite "Erasure encode/decode":
|
||||
rng = Rng.instance()
|
||||
chunker = RandomChunker.new(rng, size = dataSetSize, chunkSize = BlockSize)
|
||||
manifest = !Manifest.new(blockSize = BlockSize)
|
||||
store = CacheStore.new(cacheSize = (dataSetSize * 2), chunkSize = BlockSize)
|
||||
store = MemoryStore.new(capacity = (dataSetSize * 2), chunkSize = BlockSize)
|
||||
erasure = Erasure.new(store, leoEncoderProvider, leoDecoderProvider)
|
||||
|
||||
while (
|
||||
|
Loading…
x
Reference in New Issue
Block a user