Skip to content

Commit cb46e97

Browse files
committed
Fix reschedule async fsync test
This commit fixes the reschedule async fsync test in index service tests. This test was passing for the wrong reason. Namely, the test was trying to set translog durability to async, fire off an indexing request, and then assert that the translog eventually got fsynced. The problem here is that in the course of issuing the indexing request, a mapping update is trigger. The mapping update triggers the index settings to be refreshed. Since the test did not issue a cluster state update to change the durability from request to async but instead did this directly through index service, the mapping update flops the durability back to async. This means that when the indexing request executes, an fsync is performed after the request and the assertoin that an fsync is not needed passes but for the wrong reason (in short: the test wanted it to pass because an async fsync fired, but instead it passed because a request async fired). This commit fixes this by going through the index settings API so that a proper cluster state update is triggered and so the mapping update does not flop the durability back to request.
1 parent 50b617f commit cb46e97

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

core/src/test/java/org/elasticsearch/index/IndexServiceTests.java

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -238,31 +238,43 @@ public void testAsyncFsyncActuallyWorks() throws Exception {
238238
}
239239

240240
public void testRescheduleAsyncFsync() throws Exception {
241-
Settings settings = Settings.builder()
242-
.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), "100ms") // very often :)
243-
.put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.REQUEST)
241+
final Settings settings = Settings.builder()
242+
.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), "100ms")
243+
.put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.REQUEST)
244244
.build();
245-
IndexService indexService = createIndex("test", settings);
245+
final IndexService indexService = createIndex("test", settings);
246246
ensureGreen("test");
247247
assertNull(indexService.getFsyncTask());
248-
IndexMetaData metaData = IndexMetaData.builder(indexService.getMetaData()).settings(Settings.builder().put(indexService.getMetaData().getSettings()).put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.ASYNC)).build();
249-
indexService.updateMetaData(metaData);
248+
249+
client()
250+
.admin()
251+
.indices()
252+
.prepareUpdateSettings("test")
253+
.setSettings(Settings.builder().put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.ASYNC))
254+
.get();
255+
250256
assertNotNull(indexService.getFsyncTask());
251-
assertTrue(indexService.getRefreshTask().mustReschedule());
257+
assertTrue(indexService.getFsyncTask().mustReschedule());
252258
client().prepareIndex("test", "test", "1").setSource("{\"foo\": \"bar\"}", XContentType.JSON).get();
253-
IndexShard shard = indexService.getShard(0);
254-
assertBusy(() -> {
255-
assertFalse(shard.getTranslog().syncNeeded());
256-
});
257-
258-
metaData = IndexMetaData.builder(indexService.getMetaData()).settings(Settings.builder().put(indexService.getMetaData().getSettings()).put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.REQUEST)).build();
259-
indexService.updateMetaData(metaData);
259+
assertNotNull(indexService.getFsyncTask());
260+
final IndexShard shard = indexService.getShard(0);
261+
assertBusy(() -> assertFalse(shard.getTranslog().syncNeeded()));
262+
263+
client()
264+
.admin()
265+
.indices()
266+
.prepareUpdateSettings("test")
267+
.setSettings(Settings.builder().put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.REQUEST))
268+
.get();
260269
assertNull(indexService.getFsyncTask());
261270

262-
metaData = IndexMetaData.builder(indexService.getMetaData()).settings(Settings.builder().put(indexService.getMetaData().getSettings()).put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.ASYNC)).build();
263-
indexService.updateMetaData(metaData);
271+
client()
272+
.admin()
273+
.indices()
274+
.prepareUpdateSettings("test")
275+
.setSettings(Settings.builder().put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.ASYNC))
276+
.get();
264277
assertNotNull(indexService.getFsyncTask());
265-
266278
}
267279

268280
public void testIllegalFsyncInterval() {

0 commit comments

Comments
 (0)