@@ -51,12 +51,12 @@ public void testBasics() throws Exception {
51
51
long fromSeqNo = randomNonNegativeLong ();
52
52
long toSeqNo = randomLongBetween (fromSeqNo , Long .MAX_VALUE );
53
53
// Empty engine
54
- try (Translog .Snapshot snapshot = engine .newChangesSnapshot ("test" , mapperService , fromSeqNo , toSeqNo , true )) {
54
+ try (Translog .Snapshot snapshot = engine .newChangesSnapshot ("test" , mapperService , fromSeqNo , toSeqNo , true , randomBoolean () )) {
55
55
IllegalStateException error = expectThrows (IllegalStateException .class , () -> drainAll (snapshot ));
56
56
assertThat (error .getMessage (),
57
57
containsString ("Not all operations between from_seqno [" + fromSeqNo + "] and to_seqno [" + toSeqNo + "] found" ));
58
58
}
59
- try (Translog .Snapshot snapshot = engine .newChangesSnapshot ("test" , mapperService , fromSeqNo , toSeqNo , false )) {
59
+ try (Translog .Snapshot snapshot = engine .newChangesSnapshot ("test" , mapperService , fromSeqNo , toSeqNo , false , randomBoolean () )) {
60
60
assertThat (snapshot , SnapshotMatchers .size (0 ));
61
61
}
62
62
int numOps = between (1 , 100 );
@@ -83,17 +83,17 @@ public void testBasics() throws Exception {
83
83
toSeqNo = randomLongBetween (fromSeqNo , numOps * 2 );
84
84
85
85
Engine .Searcher searcher = engine .acquireSearcher ("test" , Engine .SearcherScope .INTERNAL );
86
- try (Translog .Snapshot snapshot = new LuceneChangesSnapshot (
87
- searcher , mapperService , between (1 , LuceneChangesSnapshot .DEFAULT_BATCH_SIZE ), fromSeqNo , toSeqNo , false )) {
86
+ try (Translog .Snapshot snapshot = new LuceneChangesSnapshot (searcher , mapperService ,
87
+ between (1 , LuceneChangesSnapshot .DEFAULT_BATCH_SIZE ), fromSeqNo , toSeqNo , false , randomBoolean () )) {
88
88
searcher = null ;
89
89
assertThat (snapshot , SnapshotMatchers .size (0 ));
90
90
} finally {
91
91
IOUtils .close (searcher );
92
92
}
93
93
94
94
searcher = engine .acquireSearcher ("test" , Engine .SearcherScope .INTERNAL );
95
- try (Translog .Snapshot snapshot = new LuceneChangesSnapshot (
96
- searcher , mapperService , between (1 , LuceneChangesSnapshot .DEFAULT_BATCH_SIZE ), fromSeqNo , toSeqNo , true )) {
95
+ try (Translog .Snapshot snapshot = new LuceneChangesSnapshot (searcher , mapperService ,
96
+ between (1 , LuceneChangesSnapshot .DEFAULT_BATCH_SIZE ), fromSeqNo , toSeqNo , true , randomBoolean () )) {
97
97
searcher = null ;
98
98
IllegalStateException error = expectThrows (IllegalStateException .class , () -> drainAll (snapshot ));
99
99
assertThat (error .getMessage (),
@@ -105,16 +105,16 @@ searcher, mapperService, between(1, LuceneChangesSnapshot.DEFAULT_BATCH_SIZE), f
105
105
fromSeqNo = randomLongBetween (0 , refreshedSeqNo );
106
106
toSeqNo = randomLongBetween (refreshedSeqNo + 1 , numOps * 2 );
107
107
Engine .Searcher searcher = engine .acquireSearcher ("test" , Engine .SearcherScope .INTERNAL );
108
- try (Translog .Snapshot snapshot = new LuceneChangesSnapshot (
109
- searcher , mapperService , between (1 , LuceneChangesSnapshot .DEFAULT_BATCH_SIZE ), fromSeqNo , toSeqNo , false )) {
108
+ try (Translog .Snapshot snapshot = new LuceneChangesSnapshot (searcher , mapperService ,
109
+ between (1 , LuceneChangesSnapshot .DEFAULT_BATCH_SIZE ), fromSeqNo , toSeqNo , false , randomBoolean () )) {
110
110
searcher = null ;
111
111
assertThat (snapshot , SnapshotMatchers .containsSeqNoRange (fromSeqNo , refreshedSeqNo ));
112
112
} finally {
113
113
IOUtils .close (searcher );
114
114
}
115
115
searcher = engine .acquireSearcher ("test" , Engine .SearcherScope .INTERNAL );
116
- try (Translog .Snapshot snapshot = new LuceneChangesSnapshot (
117
- searcher , mapperService , between (1 , LuceneChangesSnapshot .DEFAULT_BATCH_SIZE ), fromSeqNo , toSeqNo , true )) {
116
+ try (Translog .Snapshot snapshot = new LuceneChangesSnapshot (searcher , mapperService ,
117
+ between (1 , LuceneChangesSnapshot .DEFAULT_BATCH_SIZE ), fromSeqNo , toSeqNo , true , randomBoolean () )) {
118
118
searcher = null ;
119
119
IllegalStateException error = expectThrows (IllegalStateException .class , () -> drainAll (snapshot ));
120
120
assertThat (error .getMessage (),
@@ -124,8 +124,8 @@ searcher, mapperService, between(1, LuceneChangesSnapshot.DEFAULT_BATCH_SIZE), f
124
124
}
125
125
toSeqNo = randomLongBetween (fromSeqNo , refreshedSeqNo );
126
126
searcher = engine .acquireSearcher ("test" , Engine .SearcherScope .INTERNAL );
127
- try (Translog .Snapshot snapshot = new LuceneChangesSnapshot (
128
- searcher , mapperService , between (1 , LuceneChangesSnapshot .DEFAULT_BATCH_SIZE ), fromSeqNo , toSeqNo , true )) {
127
+ try (Translog .Snapshot snapshot = new LuceneChangesSnapshot (searcher , mapperService ,
128
+ between (1 , LuceneChangesSnapshot .DEFAULT_BATCH_SIZE ), fromSeqNo , toSeqNo , true , randomBoolean () )) {
129
129
searcher = null ;
130
130
assertThat (snapshot , SnapshotMatchers .containsSeqNoRange (fromSeqNo , toSeqNo ));
131
131
} finally {
@@ -135,7 +135,8 @@ searcher, mapperService, between(1, LuceneChangesSnapshot.DEFAULT_BATCH_SIZE), f
135
135
// Get snapshot via engine will auto refresh
136
136
fromSeqNo = randomLongBetween (0 , numOps - 1 );
137
137
toSeqNo = randomLongBetween (fromSeqNo , numOps - 1 );
138
- try (Translog .Snapshot snapshot = engine .newChangesSnapshot ("test" , mapperService , fromSeqNo , toSeqNo , randomBoolean ())) {
138
+ try (Translog .Snapshot snapshot =
139
+ engine .newChangesSnapshot ("test" , mapperService , fromSeqNo , toSeqNo , randomBoolean (), randomBoolean ())) {
139
140
assertThat (snapshot , SnapshotMatchers .containsSeqNoRange (fromSeqNo , toSeqNo ));
140
141
}
141
142
}
@@ -166,7 +167,8 @@ public void testSkipNonRootOfNestedDocuments() throws Exception {
166
167
long maxSeqNo = engine .getLocalCheckpointTracker ().getMaxSeqNo ();
167
168
engine .refresh ("test" );
168
169
Engine .Searcher searcher = engine .acquireSearcher ("test" , Engine .SearcherScope .INTERNAL );
169
- try (Translog .Snapshot snapshot = new LuceneChangesSnapshot (searcher , mapperService , between (1 , 100 ), 0 , maxSeqNo , false )) {
170
+ try (Translog .Snapshot snapshot =
171
+ new LuceneChangesSnapshot (searcher , mapperService , between (1 , 100 ), 0 , maxSeqNo , false , randomBoolean ())) {
170
172
assertThat (snapshot .totalOperations (), equalTo (seqNoToTerm .size ()));
171
173
Translog .Operation op ;
172
174
while ((op = snapshot .next ()) != null ) {
@@ -219,7 +221,7 @@ public void testUpdateAndReadChangesConcurrently() throws Exception {
219
221
220
222
public void testAccessStoredFieldsSequentially () throws Exception {
221
223
try (Store store = createStore ();
222
- Engine engine = createEngine (defaultSettings , store , createTempDir (), NoMergePolicy .INSTANCE )) {
224
+ InternalEngine engine = createEngine (defaultSettings , store , createTempDir (), NoMergePolicy .INSTANCE )) {
223
225
int smallBatch = between (5 , 9 );
224
226
long seqNo = 0 ;
225
227
for (int i = 0 ; i < smallBatch ; i ++) {
@@ -236,28 +238,36 @@ public void testAccessStoredFieldsSequentially() throws Exception {
236
238
// disable optimization for a small batch
237
239
Translog .Operation op ;
238
240
try (LuceneChangesSnapshot snapshot = (LuceneChangesSnapshot ) engine .newChangesSnapshot (
239
- "test" , createMapperService ("test" ), 0L , between (1 , smallBatch ), false )) {
241
+ "test" , createMapperService ("test" ), 0L , between (1 , smallBatch ), false , randomBoolean () )) {
240
242
while ((op = snapshot .next ()) != null ) {
241
243
assertFalse (op .toString (), snapshot .useSequentialStoredFieldsReader ());
242
244
}
243
245
assertFalse (snapshot .useSequentialStoredFieldsReader ());
244
246
}
245
247
// disable optimization for non-sequential accesses
246
248
try (LuceneChangesSnapshot snapshot = (LuceneChangesSnapshot ) engine .newChangesSnapshot (
247
- "test" , createMapperService ("test" ), between (1 , 3 ), between (20 , 100 ), false )) {
249
+ "test" , createMapperService ("test" ), between (1 , 3 ), between (20 , 100 ), false , randomBoolean () )) {
248
250
while ((op = snapshot .next ()) != null ) {
249
251
assertFalse (op .toString (), snapshot .useSequentialStoredFieldsReader ());
250
252
}
251
253
assertFalse (snapshot .useSequentialStoredFieldsReader ());
252
254
}
253
255
// enable optimization for sequential access of 10+ docs
254
256
try (LuceneChangesSnapshot snapshot = (LuceneChangesSnapshot ) engine .newChangesSnapshot (
255
- "test" , createMapperService ("test" ), 11 , between (21 , 100 ), false )) {
257
+ "test" , createMapperService ("test" ), 11 , between (21 , 100 ), false , true )) {
256
258
while ((op = snapshot .next ()) != null ) {
257
259
assertTrue (op .toString (), snapshot .useSequentialStoredFieldsReader ());
258
260
}
259
261
assertTrue (snapshot .useSequentialStoredFieldsReader ());
260
262
}
263
+ // disable optimization if snapshot is accessed by multiple consumers
264
+ try (LuceneChangesSnapshot snapshot = (LuceneChangesSnapshot ) engine .newChangesSnapshot (
265
+ "test" , createMapperService ("test" ), 11 , between (21 , 100 ), false , false )) {
266
+ while ((op = snapshot .next ()) != null ) {
267
+ assertFalse (op .toString (), snapshot .useSequentialStoredFieldsReader ());
268
+ }
269
+ assertFalse (snapshot .useSequentialStoredFieldsReader ());
270
+ }
261
271
}
262
272
}
263
273
@@ -284,7 +294,8 @@ void pullOperations(InternalEngine follower) throws IOException {
284
294
long fromSeqNo = followerCheckpoint + 1 ;
285
295
long batchSize = randomLongBetween (0 , 100 );
286
296
long toSeqNo = Math .min (fromSeqNo + batchSize , leaderCheckpoint );
287
- try (Translog .Snapshot snapshot = leader .newChangesSnapshot ("test" , mapperService , fromSeqNo , toSeqNo , true )) {
297
+ try (Translog .Snapshot snapshot =
298
+ leader .newChangesSnapshot ("test" , mapperService , fromSeqNo , toSeqNo , true , randomBoolean ())) {
288
299
translogHandler .run (follower , snapshot );
289
300
}
290
301
}
@@ -330,7 +341,7 @@ private List<Translog.Operation> drainAll(Translog.Snapshot snapshot) throws IOE
330
341
public void testOverFlow () throws Exception {
331
342
long fromSeqNo = randomLongBetween (0 , 5 );
332
343
long toSeqNo = randomLongBetween (Long .MAX_VALUE - 5 , Long .MAX_VALUE );
333
- try (Translog .Snapshot snapshot = engine .newChangesSnapshot ("test" , mapperService , fromSeqNo , toSeqNo , true )) {
344
+ try (Translog .Snapshot snapshot = engine .newChangesSnapshot ("test" , mapperService , fromSeqNo , toSeqNo , true , randomBoolean () )) {
334
345
IllegalStateException error = expectThrows (IllegalStateException .class , () -> drainAll (snapshot ));
335
346
assertThat (error .getMessage (),
336
347
containsString ("Not all operations between from_seqno [" + fromSeqNo + "] and to_seqno [" + toSeqNo + "] found" ));
0 commit comments