java里的external,Java VersionType.EXTERNAL属性代码示例

public void testOutOfOrderSequenceNumbersWithVersionConflict() throws IOException {

final List operations = new ArrayList<>();

final int numberOfOperations = randomIntBetween(16, 32);

final Document document = testDocumentWithTextField();

final AtomicLong sequenceNumber = new AtomicLong();

final Engine.Operation.Origin origin = randomFrom(LOCAL_TRANSLOG_RECOVERY, PEER_RECOVERY, PRIMARY, REPLICA);

final LongSupplier sequenceNumberSupplier =

origin == PRIMARY ? () -> SequenceNumbersService.UNASSIGNED_SEQ_NO : sequenceNumber::getAndIncrement;

document.add(new Field(SourceFieldMapper.NAME, BytesReference.toBytes(B_1), SourceFieldMapper.Defaults.FIELD_TYPE));

final ParsedDocument doc = testParsedDocument("1", "test", null, document, B_1, null);

final Term uid = newUid(doc);

for (int i = 0; i < numberOfOperations; i++) {

if (randomBoolean()) {

final Engine.Index index = new Engine.Index(

uid,

doc,

sequenceNumberSupplier.getAsLong(),

1,

i,

VersionType.EXTERNAL,

origin,

System.nanoTime(),

IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP,

false);

operations.add(index);

} else {

final Engine.Delete delete = new Engine.Delete(

"test",

"1",

uid,

sequenceNumberSupplier.getAsLong(),

1,

i,

VersionType.EXTERNAL,

origin,

System.nanoTime());

operations.add(delete);

}

}

final boolean exists = operations.get(operations.size() - 1) instanceof Engine.Index;

Randomness.shuffle(operations);

for (final Engine.Operation operation : operations) {

if (operation instanceof Engine.Index) {

engine.index((Engine.Index) operation);

} else {

engine.delete((Engine.Delete) operation);

}

}

final long expectedLocalCheckpoint;

if (origin == PRIMARY) {

// we can only advance as far as the number of operations that did not conflict

int count = 0;

// each time the version increments as we walk the list, that counts as a successful operation

long version = -1;

for (int i = 0; i < numberOfOperations; i++) {

if (operations.get(i).version() >= version) {

count++;

version = operations.get(i).version();

}

}

// sequence numbers start at zero, so the expected local checkpoint is the number of successful operations minus one

expectedLocalCheckpoint = count - 1;

} else {

expectedLocalCheckpoint = numberOfOperations - 1;

}

assertThat(engine.seqNoService().getLocalCheckpoint(), equalTo(expectedLocalCheckpoint));

try (Engine.GetResult result = engine.get(new Engine.Get(true, uid))) {

assertThat(result.exists(), equalTo(exists));

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值