Added additional assertion that the view to remove was actually registered.

This commit is contained in:
Simon Willnauer 2015-05-18 17:04:54 +02:00
parent bc810e1320
commit a21e4449b7
2 changed files with 16 additions and 5 deletions

View File

@ -125,7 +125,8 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
@Override
public void handle(View view) {
logger.trace("closing view starting at translog [{}]", view.minTranslogGeneration());
outstandingViews.remove(this);
boolean removed = outstandingViews.remove(view);
assert removed : "View was never set but was supposed to be removed";
}
};
@ -448,18 +449,18 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
* @see org.elasticsearch.index.translog.Translog.Delete
*/
public Location add(Operation operation) throws TranslogException {
ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(bigArrays);
final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(bigArrays);
try {
final BufferedChecksumStreamOutput checksumStreamOutput = new BufferedChecksumStreamOutput(out);
final long start = out.position();
out.skip(RamUsageEstimator.NUM_BYTES_INT);
writeOperationNoSize(checksumStreamOutput, operation);
long end = out.position();
int operationSize = (int) (out.position() - RamUsageEstimator.NUM_BYTES_INT - start);
final long end = out.position();
final int operationSize = (int) (end - RamUsageEstimator.NUM_BYTES_INT - start);
out.seek(start);
out.writeInt(operationSize);
out.seek(end);
ReleasablePagedBytesReference bytes = out.bytes();
final ReleasablePagedBytesReference bytes = out.bytes();
try (ReleasableLock lock = readLock.acquire()) {
Location location = current.add(bytes);
if (config.isSyncOnEachOperation()) {
@ -1768,4 +1769,11 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
}
}
/**
* The number of currently open views
*/
int getNumOpenViews() {
return outstandingViews.size();
}
}

View File

@ -25,6 +25,7 @@ import org.apache.lucene.index.Term;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.ByteArrayDataOutput;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
@ -70,6 +71,7 @@ import static org.hamcrest.Matchers.*;
/**
*
*/
@LuceneTestCase.SuppressFileSystems("ExtrasFS")
public class TranslogTests extends ElasticsearchTestCase {
protected final ShardId shardId = new ShardId(new Index("index"), 1);
@ -106,6 +108,7 @@ public class TranslogTests extends ElasticsearchTestCase {
@After
public void tearDown() throws Exception {
try {
assertEquals("there are still open views", 0, translog.getNumOpenViews());
translog.close();
} finally {
super.tearDown();