Simplify IndexingMemoryController#checkIdle

This commit further simplifies IndexingMemoryController#checkIdle after
the changes in #15251.
This commit is contained in:
Jason Tedor 2015-12-04 16:01:15 -05:00
parent 5a391f116b
commit b1a67b1c69
2 changed files with 17 additions and 27 deletions

View File

@ -286,33 +286,23 @@ public class IndexingMemoryController extends AbstractLifecycleComponent<Indexin
return System.nanoTime(); return System.nanoTime();
} }
/** ask this shard to check now whether it is inactive, and reduces its indexing and translog buffers if so. returns Boolean.TRUE if /**
* it did deactive, Boolean.FALSE if it did not, and null if the shard is unknown */ * ask this shard to check now whether it is inactive, and reduces its indexing and translog buffers if so.
protected Boolean checkIdle(IndexShard shard) { * return false if the shard is not idle, otherwise true
String ignoreReason = null; // eclipse compiler does not know it is really final */
if (shard != null) { protected boolean checkIdle(IndexShard shard) {
try { try {
if (shard.checkIdle()) { boolean idle = shard.checkIdle();
if (idle && logger.isDebugEnabled()) {
logger.debug("marking shard {} as inactive (inactive_time[{}]) indexing wise", logger.debug("marking shard {} as inactive (inactive_time[{}]) indexing wise",
shard.shardId(), shard.shardId(),
shard.getInactiveTime()); shard.getInactiveTime());
return Boolean.TRUE;
} }
return Boolean.FALSE; return idle;
} catch (EngineClosedException e) { } catch (EngineClosedException | FlushNotAllowedEngineException e) {
// ignore logger.trace("ignore [{}] while marking shard {} as inactive", e.getClass().getSimpleName(), shard.shardId());
ignoreReason = "EngineClosedException"; return true;
} catch (FlushNotAllowedEngineException e) {
// ignore
ignoreReason = "FlushNotAllowedEngineException";
} }
} else {
ignoreReason = "shard not found";
}
if (ignoreReason != null) {
logger.trace("ignore [{}] while marking shard {} as inactive", ignoreReason, shard.shardId());
}
return null;
} }
@Override @Override

View File

@ -93,11 +93,11 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase {
} }
@Override @Override
protected Boolean checkIdle(IndexShard shard) { protected boolean checkIdle(IndexShard shard) {
final TimeValue inactiveTime = settings.getAsTime(IndexShard.INDEX_SHARD_INACTIVE_TIME_SETTING, TimeValue.timeValueMinutes(5)); final TimeValue inactiveTime = settings.getAsTime(IndexShard.INDEX_SHARD_INACTIVE_TIME_SETTING, TimeValue.timeValueMinutes(5));
Long ns = lastIndexTimeNanos.get(shard); Long ns = lastIndexTimeNanos.get(shard);
if (ns == null) { if (ns == null) {
return null; return true;
} else if (currentTimeInNanos() - ns >= inactiveTime.nanos()) { } else if (currentTimeInNanos() - ns >= inactiveTime.nanos()) {
indexingBuffers.put(shard, INACTIVE); indexingBuffers.put(shard, INACTIVE);
translogBuffers.put(shard, INACTIVE); translogBuffers.put(shard, INACTIVE);