Skip to content

Commit 3e971ae

Browse files
committed
bugfix in trans buffer
1 parent 589b957 commit 3e971ae

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

ucm/store/cache/cc/trans_buffer.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,24 +348,28 @@ Status TransBuffer::Setup(const Config& config)
348348
TransBuffer::Handle TransBuffer::Get(const Detail::BlockId& blockId, size_t shardIdx)
349349
{
350350
auto iBucket = Hash(blockId, shardIdx);
351+
bool owner = false;
351352
strategy_->BucketLock(iBucket);
352-
auto iNode = FindAt(iBucket, blockId, shardIdx);
353-
strategy_->BucketUnlock(iBucket);
354-
if (iNode != invalidIndex) { return Handle{this, iNode, false}; }
353+
auto iNode = FindAt(iBucket, blockId, shardIdx, owner);
354+
if (iNode != invalidIndex) {
355+
strategy_->BucketUnlock(iBucket);
356+
return Handle{this, iNode, owner};
357+
}
355358
iNode = Alloc(blockId, shardIdx);
356-
strategy_->BucketLock(iBucket);
357359
MoveTo(iBucket, iNode);
358360
strategy_->BucketUnlock(iBucket);
359361
return Handle(this, iNode, true);
360362
}
361363

362-
size_t TransBuffer::FindAt(size_t iBucket, const Detail::BlockId& blockId, size_t shardIdx)
364+
size_t TransBuffer::FindAt(size_t iBucket, const Detail::BlockId& blockId, size_t shardIdx,
365+
bool& owner)
363366
{
364367
auto iNode = strategy_->FirstAt(iBucket);
365368
while (iNode != invalidIndex) {
366369
auto meta = strategy_->MetaAt(iNode);
367370
strategy_->NodeLock(iNode);
368371
if (meta->block == blockId && meta->shard == shardIdx) {
372+
owner = meta->reference == 0;
369373
++meta->reference;
370374
strategy_->NodeUnlock(iNode);
371375
break;

ucm/store/cache/cc/trans_buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class TransBuffer {
101101
Handle Get(const Detail::BlockId& blockId, size_t shardIdx);
102102

103103
private:
104-
size_t FindAt(size_t iBucket, const Detail::BlockId& blockId, size_t shardIdx);
104+
size_t FindAt(size_t iBucket, const Detail::BlockId& blockId, size_t shardIdx, bool& owner);
105105
size_t Alloc(const Detail::BlockId& blockId, size_t shardIdx);
106106
void MoveTo(size_t iBucket, size_t iNode);
107107
void Remove(size_t iNode);

0 commit comments

Comments
 (0)