Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of IndexServiceTest #10628

Merged
merged 2 commits into from Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions devs/docs/es-backports.rst
Expand Up @@ -473,6 +473,7 @@ should be crossed out as well.
- [x] 302d29c8705 Trim local translog in peer recovery (#44756)
- [x] 6215f98fa68 Remove fileBasedRecovery flag (#45131)
- [x] 01287eacb2f Use index for peer recovery instead of translog (#45136)
- [x] 3c352a85963 Make setting index.translog.sync_interval be dynamic (#37382))
- [x] c4b831645cb MINOR: Remove some deadcode in NodeEnv and Related (#34133)

Below lists deferred patches. In-between patches that we applied or skipped
Expand Down
36 changes: 22 additions & 14 deletions server/src/main/java/org/elasticsearch/index/IndexService.java
Expand Up @@ -104,7 +104,7 @@ public class IndexService extends AbstractIndexComponent implements IndicesClust
private volatile AsyncRetentionLeaseSyncTask retentionLeaseSyncTask;

// don't convert to Setting<> and register... we only set this in tests and register via a plugin
private final String INDEX_TRANSLOG_RETENTION_CHECK_INTERVAL_SETTING = "index.translog.retention.check_interval";
public static final String INDEX_TRANSLOG_RETENTION_CHECK_INTERVAL_SETTING = "index.translog.retention.check_interval";

private final AsyncTrimTranslogTask trimTranslogTask;
private final ThreadPool threadPool;
Expand Down Expand Up @@ -159,7 +159,7 @@ public IndexService(
this.trimTranslogTask = new AsyncTrimTranslogTask(this);
this.globalCheckpointTask = new AsyncGlobalCheckpointTask(this);
this.retentionLeaseSyncTask = new AsyncRetentionLeaseSyncTask(this);
rescheduleFsyncTask(indexSettings.getTranslogDurability());
updateFsyncTaskIfNecessary();
}

public enum IndexCreationContext {
Expand Down Expand Up @@ -513,8 +513,6 @@ public IndexMetadata getMetadata() {

@Override
public synchronized void updateMetadata(final IndexMetadata currentIndexMetadata, final IndexMetadata newIndexMetadata) {
final Translog.Durability oldTranslogDurability = indexSettings.getTranslogDurability();

final boolean updateIndexMetadata = indexSettings.updateIndexMetadata(newIndexMetadata);

if (Assertions.ENABLED
Expand Down Expand Up @@ -566,20 +564,23 @@ public boolean isForceExecution() {
});
rescheduleRefreshTasks();
}
final Translog.Durability durability = indexSettings.getTranslogDurability();
if (durability != oldTranslogDurability) {
rescheduleFsyncTask(durability);
mkleen marked this conversation as resolved.
Show resolved Hide resolved
}
updateFsyncTaskIfNecessary();
}
}

private void rescheduleFsyncTask(Translog.Durability durability) {
try {
if (fsyncTask != null) {
fsyncTask.close();
private void updateFsyncTaskIfNecessary() {
if (indexSettings.getTranslogDurability() == Translog.Durability.REQUEST) {
try {
if (fsyncTask != null) {
fsyncTask.close();
}
} finally {
fsyncTask = null;
}
} finally {
fsyncTask = durability == Translog.Durability.REQUEST ? null : new AsyncTranslogFSync(this);
} else if (fsyncTask == null) {
fsyncTask = new AsyncTranslogFSync(this);
} else {
fsyncTask.updateIfNeeded();
}
}

Expand Down Expand Up @@ -738,6 +739,13 @@ protected void runInternal() {
indexService.maybeFSyncTranslogs();
}

void updateIfNeeded() {
final TimeValue newInterval = indexService.getIndexSettings().getTranslogSyncInterval();
if (newInterval.equals(getInterval()) == false) {
setInterval(newInterval);
}
}

@Override
public String toString() {
return "translog_sync";
Expand Down
Expand Up @@ -66,7 +66,7 @@ public final class IndexSettings {
Setting.boolSetting("index.query.parse.allow_unmapped_fields", true, Property.IndexScope);
public static final Setting<TimeValue> INDEX_TRANSLOG_SYNC_INTERVAL_SETTING =
Setting.timeSetting("index.translog.sync_interval", TimeValue.timeValueSeconds(5), TimeValue.timeValueMillis(100),
Property.IndexScope);
Property.Dynamic, Property.IndexScope);
public static final Setting<TimeValue> INDEX_SEARCH_IDLE_AFTER =
Setting.timeSetting("index.search.idle.after", TimeValue.timeValueSeconds(30),
TimeValue.timeValueMinutes(0), Property.IndexScope, Property.Dynamic);
Expand Down Expand Up @@ -256,7 +256,7 @@ public final class IndexSettings {
private volatile List<String> defaultFields;
private final boolean defaultAllowUnmappedFields;
private volatile Translog.Durability durability;
private final TimeValue syncInterval;
private volatile TimeValue syncInterval;
private volatile TimeValue refreshInterval;
private volatile ByteSizeValue flushThresholdSize;
private volatile TimeValue translogRetentionAge;
Expand Down Expand Up @@ -388,6 +388,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
mergeSchedulerConfig::setMaxThreadAndMergeCount);
scopedSettings.addSettingsUpdateConsumer(MergeSchedulerConfig.AUTO_THROTTLE_SETTING, mergeSchedulerConfig::setAutoThrottle);
scopedSettings.addSettingsUpdateConsumer(INDEX_TRANSLOG_DURABILITY_SETTING, this::setTranslogDurability);
scopedSettings.addSettingsUpdateConsumer(INDEX_TRANSLOG_SYNC_INTERVAL_SETTING, this::setTranslogSyncInterval);
scopedSettings.addSettingsUpdateConsumer(MAX_NGRAM_DIFF_SETTING, this::setMaxNgramDiff);
scopedSettings.addSettingsUpdateConsumer(MAX_SHINGLE_DIFF_SETTING, this::setMaxShingleDiff);
scopedSettings.addSettingsUpdateConsumer(INDEX_WARMER_ENABLED_SETTING, this::setEnableWarmer);
Expand Down Expand Up @@ -598,6 +599,10 @@ public TimeValue getTranslogSyncInterval() {
return syncInterval;
}

public void setTranslogSyncInterval(TimeValue translogSyncInterval) {
this.syncInterval = translogSyncInterval;
}

/**
* Returns this interval in which the shards of this index are asynchronously refreshed. {@code -1} means async refresh is disabled.
*/
Expand Down
Expand Up @@ -88,8 +88,8 @@ public void testSelectSettingsColumn() throws Exception {

@Test
public void testSetNonDynamicTableSetting() {
assertThrows(() -> execute("alter table settings_table set (\"translog.sync_interval\"='10s')"),
isSQLError(containsString("Can't update non dynamic settings [[index.translog.sync_interval]] for open indices"),
assertThrows(() -> execute("alter table settings_table set (\"soft_deletes.enabled\"='true')"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since translog.sync_interval is dynamic now we need to test against a different non dynamic setting.

isSQLError(containsString("Can't update non dynamic settings [[index.soft_deletes.enabled]] for open indices"),
INTERNAL_ERROR,
BAD_REQUEST,
4000));
Expand Down