Skip to content

Commit

Permalink
Read state concurrent access bugfix- atomicity in accessing fields of…
Browse files Browse the repository at this point in the history
… shard holder
  • Loading branch information
Sunjeet committed Oct 7, 2023
1 parent 547fcab commit a739efc
Showing 1 changed file with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,63 +360,76 @@ public int readOrdinal(int ordinal, int fieldIndex) {
@Override
public int readInt(int ordinal, int fieldIndex) {
sampler.recordFieldAccess(fieldIndex);
HollowObjectTypeReadStateShard shard = shardsVolatile.shards[ordinal & shardsVolatile.shardNumberMask];
ShardsHolder shardsHolder = shardsVolatile; // this read can return a stale shardHolder with greater or lesser than current
// num shards but maxOrdinal remains same across stale vs current. So given this
// atomic assignment below operations on a stale shards holder will be legal
// SNAP: Here: but which shard to map to should probably be re-computed right, if
// the we got a stale shard here?
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
return shard.readInt(ordinal >> shard.shardOrdinalShift, fieldIndex);
}

@Override
public float readFloat(int ordinal, int fieldIndex) {
sampler.recordFieldAccess(fieldIndex);
HollowObjectTypeReadStateShard shard = shardsVolatile.shards[ordinal & shardsVolatile.shardNumberMask];
ShardsHolder shardsHolder = shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
return shard.readFloat(ordinal >> shard.shardOrdinalShift, fieldIndex);
}

@Override
public double readDouble(int ordinal, int fieldIndex) {
sampler.recordFieldAccess(fieldIndex);
HollowObjectTypeReadStateShard shard = shardsVolatile.shards[ordinal & shardsVolatile.shardNumberMask];
ShardsHolder shardsHolder = shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
return shard.readDouble(ordinal >> shard.shardOrdinalShift, fieldIndex);
}

@Override
public long readLong(int ordinal, int fieldIndex) {
sampler.recordFieldAccess(fieldIndex);
HollowObjectTypeReadStateShard shard = shardsVolatile.shards[ordinal & shardsVolatile.shardNumberMask];
ShardsHolder shardsHolder = shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
return shard.readLong(ordinal >> shard.shardOrdinalShift, fieldIndex);
}

@Override
public Boolean readBoolean(int ordinal, int fieldIndex) {
sampler.recordFieldAccess(fieldIndex);
HollowObjectTypeReadStateShard shard = shardsVolatile.shards[ordinal & shardsVolatile.shardNumberMask];
ShardsHolder shardsHolder = shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
return shard.readBoolean(ordinal >> shard.shardOrdinalShift, fieldIndex);
}

@Override
public byte[] readBytes(int ordinal, int fieldIndex) {
sampler.recordFieldAccess(fieldIndex);
HollowObjectTypeReadStateShard shard = shardsVolatile.shards[ordinal & shardsVolatile.shardNumberMask];
ShardsHolder shardsHolder = shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
return shard.readBytes(ordinal >> shard.shardOrdinalShift, fieldIndex);
}

@Override
public String readString(int ordinal, int fieldIndex) {
sampler.recordFieldAccess(fieldIndex);
HollowObjectTypeReadStateShard shard = shardsVolatile.shards[ordinal & shardsVolatile.shardNumberMask];
ShardsHolder shardsHolder = shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
return shard.readString(ordinal >> shard.shardOrdinalShift, fieldIndex);
}

@Override
public boolean isStringFieldEqual(int ordinal, int fieldIndex, String testValue) {
sampler.recordFieldAccess(fieldIndex);
HollowObjectTypeReadStateShard shard = shardsVolatile.shards[ordinal & shardsVolatile.shardNumberMask];
ShardsHolder shardsHolder = shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
return shard.isStringFieldEqual(ordinal >> shard.shardOrdinalShift, fieldIndex, testValue);
}

@Override
public int findVarLengthFieldHashCode(int ordinal, int fieldIndex) {
sampler.recordFieldAccess(fieldIndex);
HollowObjectTypeReadStateShard shard = shardsVolatile.shards[ordinal & shardsVolatile.shardNumberMask];
ShardsHolder shardsHolder = shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
return shard.findVarLengthFieldHashCode(ordinal >> shard.shardOrdinalShift, fieldIndex);
}

Expand Down

0 comments on commit a739efc

Please sign in to comment.