@@ -606,7 +606,7 @@ protected final GetResult getFromSearcher(Get get, BiFunction<String, SearcherSc
606
606
final Searcher searcher = searcherFactory .apply ("get" , scope );
607
607
final DocIdAndVersion docIdAndVersion ;
608
608
try {
609
- docIdAndVersion = VersionsAndSeqNoResolver .loadDocIdAndVersion (searcher .reader (), get .uid ());
609
+ docIdAndVersion = VersionsAndSeqNoResolver .loadDocIdAndVersion (searcher .reader (), get .uid (), true );
610
610
} catch (Exception e ) {
611
611
Releasables .closeWhileHandlingException (searcher );
612
612
//TODO: A better exception goes here
@@ -1345,14 +1345,23 @@ public static class Index extends Operation {
1345
1345
private final ParsedDocument doc ;
1346
1346
private final long autoGeneratedIdTimestamp ;
1347
1347
private final boolean isRetry ;
1348
+ private final long ifSeqNoMatch ;
1349
+ private final long ifPrimaryTermMatch ;
1348
1350
1349
1351
public Index (Term uid , ParsedDocument doc , long seqNo , long primaryTerm , long version , VersionType versionType , Origin origin ,
1350
- long startTime , long autoGeneratedIdTimestamp , boolean isRetry ) {
1352
+ long startTime , long autoGeneratedIdTimestamp , boolean isRetry , long ifSeqNoMatch , long ifPrimaryTermMatch ) {
1351
1353
super (uid , seqNo , primaryTerm , version , versionType , origin , startTime );
1352
1354
assert (origin == Origin .PRIMARY ) == (versionType != null ) : "invalid version_type=" + versionType + " for origin=" + origin ;
1355
+ assert ifPrimaryTermMatch >= 0 : "ifPrimaryTermMatch [" + ifPrimaryTermMatch + "] must be non negative" ;
1356
+ assert ifSeqNoMatch == SequenceNumbers .UNASSIGNED_SEQ_NO || ifSeqNoMatch >=0 :
1357
+ "ifSeqNoMatch [" + ifSeqNoMatch + "] must be non negative or unset" ;
1358
+ assert (origin == Origin .PRIMARY ) || (ifSeqNoMatch == SequenceNumbers .UNASSIGNED_SEQ_NO && ifPrimaryTermMatch == 0 ) :
1359
+ "cas operations are only allowed if origin is primary. get [" + origin + "]" ;
1353
1360
this .doc = doc ;
1354
1361
this .isRetry = isRetry ;
1355
1362
this .autoGeneratedIdTimestamp = autoGeneratedIdTimestamp ;
1363
+ this .ifSeqNoMatch = ifSeqNoMatch ;
1364
+ this .ifPrimaryTermMatch = ifPrimaryTermMatch ;
1356
1365
}
1357
1366
1358
1367
public Index (Term uid , long primaryTerm , ParsedDocument doc ) {
@@ -1361,7 +1370,7 @@ public Index(Term uid, long primaryTerm, ParsedDocument doc) {
1361
1370
1362
1371
Index (Term uid , long primaryTerm , ParsedDocument doc , long version ) {
1363
1372
this (uid , doc , SequenceNumbers .UNASSIGNED_SEQ_NO , primaryTerm , version , VersionType .INTERNAL ,
1364
- Origin .PRIMARY , System .nanoTime (), -1 , false );
1373
+ Origin .PRIMARY , System .nanoTime (), -1 , false , SequenceNumbers . UNASSIGNED_SEQ_NO , 0 );
1365
1374
} // TEST ONLY
1366
1375
1367
1376
public ParsedDocument parsedDoc () {
@@ -1417,29 +1426,45 @@ public boolean isRetry() {
1417
1426
return isRetry ;
1418
1427
}
1419
1428
1429
+ public long getIfSeqNoMatch () {
1430
+ return ifSeqNoMatch ;
1431
+ }
1432
+
1433
+ public long getIfPrimaryTermMatch () {
1434
+ return ifPrimaryTermMatch ;
1435
+ }
1420
1436
}
1421
1437
1422
1438
public static class Delete extends Operation {
1423
1439
1424
1440
private final String type ;
1425
1441
private final String id ;
1442
+ private final long ifSeqNoMatch ;
1443
+ private final long ifPrimaryTermMatch ;
1426
1444
1427
1445
public Delete (String type , String id , Term uid , long seqNo , long primaryTerm , long version , VersionType versionType ,
1428
- Origin origin , long startTime ) {
1446
+ Origin origin , long startTime , long ifSeqNoMatch , long ifPrimaryTermMatch ) {
1429
1447
super (uid , seqNo , primaryTerm , version , versionType , origin , startTime );
1430
1448
assert (origin == Origin .PRIMARY ) == (versionType != null ) : "invalid version_type=" + versionType + " for origin=" + origin ;
1449
+ assert ifPrimaryTermMatch >= 0 : "ifPrimaryTermMatch [" + ifPrimaryTermMatch + "] must be non negative" ;
1450
+ assert ifSeqNoMatch == SequenceNumbers .UNASSIGNED_SEQ_NO || ifSeqNoMatch >=0 :
1451
+ "ifSeqNoMatch [" + ifSeqNoMatch + "] must be non negative or unset" ;
1452
+ assert (origin == Origin .PRIMARY ) || (ifSeqNoMatch == SequenceNumbers .UNASSIGNED_SEQ_NO && ifPrimaryTermMatch == 0 ) :
1453
+ "cas operations are only allowed if origin is primary. get [" + origin + "]" ;
1431
1454
this .type = Objects .requireNonNull (type );
1432
1455
this .id = Objects .requireNonNull (id );
1456
+ this .ifSeqNoMatch = ifSeqNoMatch ;
1457
+ this .ifPrimaryTermMatch = ifPrimaryTermMatch ;
1433
1458
}
1434
1459
1435
1460
public Delete (String type , String id , Term uid , long primaryTerm ) {
1436
1461
this (type , id , uid , SequenceNumbers .UNASSIGNED_SEQ_NO , primaryTerm , Versions .MATCH_ANY , VersionType .INTERNAL ,
1437
- Origin .PRIMARY , System .nanoTime ());
1462
+ Origin .PRIMARY , System .nanoTime (), SequenceNumbers . UNASSIGNED_SEQ_NO , 0 );
1438
1463
}
1439
1464
1440
1465
public Delete (Delete template , VersionType versionType ) {
1441
1466
this (template .type (), template .id (), template .uid (), template .seqNo (), template .primaryTerm (), template .version (),
1442
- versionType , template .origin (), template .startTime ());
1467
+ versionType , template .origin (), template .startTime (), SequenceNumbers . UNASSIGNED_SEQ_NO , 0 );
1443
1468
}
1444
1469
1445
1470
@ Override
@@ -1462,6 +1487,13 @@ public int estimatedSizeInBytes() {
1462
1487
return (uid ().field ().length () + uid ().text ().length ()) * 2 + 20 ;
1463
1488
}
1464
1489
1490
+ public long getIfSeqNoMatch () {
1491
+ return ifSeqNoMatch ;
1492
+ }
1493
+
1494
+ public long getIfPrimaryTermMatch () {
1495
+ return ifPrimaryTermMatch ;
1496
+ }
1465
1497
}
1466
1498
1467
1499
public static class NoOp extends Operation {
0 commit comments