mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
memStore consistently returns the same Chunk object.
This commit is contained in:
parent
e787f4c885
commit
b0d7fa2c7a
3 changed files with 16 additions and 13 deletions
|
|
@ -318,7 +318,7 @@ func (self *LazyChunkReader) ReadAt(b []byte, off int64) (read int, err error) {
|
|||
// dpaLogger.Debugf("chunk data received for %x", chunk.Key[:4])
|
||||
}
|
||||
if len(chunk.Data) == 0 {
|
||||
// dpaLogger.Debugf("No payload.")
|
||||
dpaLogger.Debugf("No payload in %x.", chunk.Key)
|
||||
return 0, notFound
|
||||
}
|
||||
self.size = chunk.Size
|
||||
|
|
|
|||
|
|
@ -159,6 +159,7 @@ func (s *memStore) getEntryCnt() uint {
|
|||
|
||||
}
|
||||
|
||||
// entry (not its copy) is going to be in memStore
|
||||
func (s *memStore) Put(entry *Chunk) {
|
||||
|
||||
if s.capacity == 0 {
|
||||
|
|
@ -193,13 +194,15 @@ func (s *memStore) Put(entry *Chunk) {
|
|||
|
||||
if node.entry.Key.isEqual(entry.Key) {
|
||||
node.updateAccess(s.accessCnt)
|
||||
if node.entry.Data == nil {
|
||||
node.entry.Size = entry.Size
|
||||
node.entry.Data = entry.Data
|
||||
if entry.Data == nil {
|
||||
entry.Size = node.entry.Size
|
||||
entry.Data = node.entry.Data
|
||||
}
|
||||
if node.entry.req == nil {
|
||||
node.entry.req = entry.req
|
||||
if entry.req == nil {
|
||||
entry.req = node.entry.req
|
||||
}
|
||||
entry.C = node.entry.C
|
||||
node.entry = entry
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -253,11 +256,7 @@ func (s *memStore) Get(hash Key) (chunk *Chunk, err error) {
|
|||
if node.entry.Key.isEqual(hash) {
|
||||
s.accessCnt++
|
||||
node.updateAccess(s.accessCnt)
|
||||
chunk = &Chunk{
|
||||
Key: hash,
|
||||
Data: node.entry.Data,
|
||||
Size: node.entry.Size,
|
||||
}
|
||||
chunk = node.entry
|
||||
if s.dbAccessCnt-node.lastDBaccess > dbForceUpdateAccessCnt {
|
||||
s.dbAccessCnt++
|
||||
node.lastDBaccess = s.dbAccessCnt
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ func (self *NetStore) Put(entry *Chunk) {
|
|||
|
||||
func (self *NetStore) put(entry *Chunk) {
|
||||
self.localStore.Put(entry)
|
||||
dpaLogger.Debugf("NetStore.put: localStore.Put of %064x completed.", entry.Key)
|
||||
dpaLogger.Debugf("NetStore.put: localStore.Put of %064x completed, %d bytes (%p).", entry.Key, len(entry.Data), entry)
|
||||
go self.store(entry)
|
||||
// only send responses once
|
||||
dpaLogger.Debugf("NetStore.put: req: %#v", entry.req)
|
||||
|
|
@ -82,7 +82,9 @@ func (self *NetStore) put(entry *Chunk) {
|
|||
func (self *NetStore) addStoreRequest(req *storeRequestMsgData) {
|
||||
self.lock.Lock()
|
||||
defer self.lock.Unlock()
|
||||
dpaLogger.Debugf("NetStore.addStoreRequest: req = %#v", req)
|
||||
chunk, err := self.localStore.Get(req.Key)
|
||||
dpaLogger.Debugf("NetStore.addStoreRequest: chunk reference %p", chunk)
|
||||
// we assume that a returned chunk is the one stored in the memory cache
|
||||
if err != nil {
|
||||
chunk = &Chunk{
|
||||
|
|
@ -91,6 +93,7 @@ func (self *NetStore) addStoreRequest(req *storeRequestMsgData) {
|
|||
Size: int64(req.Size),
|
||||
}
|
||||
} else if chunk.Data == nil {
|
||||
// response to a search request
|
||||
chunk.Data = req.Data
|
||||
chunk.Size = int64(req.Size)
|
||||
} else {
|
||||
|
|
@ -116,7 +119,7 @@ func (self *NetStore) Get(key Key) (chunk *Chunk, err error) {
|
|||
dpaLogger.Debugf("NetStore.Get: %064x request time out ", key)
|
||||
err = notFound
|
||||
case <-chunk.req.C:
|
||||
dpaLogger.Debugf("NetStore.get: %064x retrieved", key)
|
||||
dpaLogger.Debugf("NetStore.Get: %064x retrieved, %d bytes (%p)", key, len(chunk.Data), chunk)
|
||||
|
||||
}
|
||||
return
|
||||
|
|
@ -137,6 +140,7 @@ func (self *NetStore) get(key Key) (chunk *Chunk) {
|
|||
|
||||
if chunk.req == nil {
|
||||
chunk.req = new(requestStatus)
|
||||
chunk.req.C = make(chan bool)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue