Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -982,22 +982,8 @@ public Void call() throws IOException {
}

/**
* Snapshot this stores memstore. Call before running
* {@link #flushCache(long, MemStoreSnapshot, MonitoredTask, ThroughputController,
* FlushLifeCycleTracker)}
* so it has some work to do.
*/
void snapshot() {
this.lock.writeLock().lock();
try {
this.memstore.snapshot();
} finally {
this.lock.writeLock().unlock();
}
}

/**
* Write out current snapshot. Presumes {@link #snapshot()} has been called previously.
* Write out current snapshot. Presumes {@code StoreFlusherImpl.prepare()} has been called
* previously.
* @param logCacheFlushId flush sequence number
* @return The path name of the tmp file to which the store was flushed
* @throws IOException if exception occurs during process
Expand Down Expand Up @@ -1240,9 +1226,6 @@ private boolean updateStorefiles(List<HStoreFile> sfs, long snapshotId) throws I
this.lock.writeLock().lock();
try {
this.storeEngine.getStoreFileManager().insertNewFiles(sfs);
if (snapshotId > 0) {
this.memstore.clearSnapshot(snapshotId);
}
} finally {
// We need the lock, as long as we are updating the storeFiles
// or changing the memstore. Let us release it before calling
Expand All @@ -1251,6 +1234,13 @@ private boolean updateStorefiles(List<HStoreFile> sfs, long snapshotId) throws I
// the lock.
this.lock.writeLock().unlock();
}
// We do not need to call clearSnapshot method inside the write lock.
// The clearSnapshot itself is thread safe, which can be called at the same time with other
// memstore operations expect snapshot and clearSnapshot. And for these two methods, in HRegion
// we can guarantee that there is only one onging flush, so they will be no race.
if (snapshotId > 0) {
this.memstore.clearSnapshot(snapshotId);
}
// notify to be called here - only in case of flushes
notifyChangedReadersObservers(sfs);
if (LOG.isTraceEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,21 +461,15 @@ public void testResolve() throws Exception {

/**
* Flush the memstore
* @param storeFilesSize
* @throws IOException
*/
private void flush(int storeFilesSize) throws IOException{
this.store.snapshot();
flushStore(store, id++);
Assert.assertEquals(storeFilesSize, this.store.getStorefiles().size());
Assert.assertEquals(0, ((AbstractMemStore)this.store.memstore).getActive().getCellsCount());
}

/**
* Flush the memstore
* @param store
* @param id
* @throws IOException
*/
private static void flushStore(HMobStore store, long id) throws IOException {
StoreFlushContext storeFlushCtx = store.createFlushContext(id, FlushLifeCycleTracker.DUMMY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,7 @@ public void testGet_FromMemStoreAndFiles() throws IOException {
assertCheck();
}

private void flush(int storeFilessize) throws IOException{
this.store.snapshot();
private void flush(int storeFilessize) throws IOException {
flushStore(store, id++);
assertEquals(storeFilessize, this.store.getStorefiles().size());
assertEquals(0, ((AbstractMemStore)this.store.memstore).getActive().getCellsCount());
Expand Down Expand Up @@ -801,7 +800,6 @@ private List<Cell> getKeyValueSet(long[] timestamps, int numRows,

/**
* Test to ensure correctness when using Stores with multiple timestamps
* @throws IOException
*/
@Test
public void testMultipleTimestamps() throws IOException {
Expand All @@ -816,7 +814,6 @@ public void testMultipleTimestamps() throws IOException {
this.store.add(kv, null);
}

this.store.snapshot();
flushStore(store, id++);

List<Cell> kvList2 = getKeyValueSet(timestamps2,numRows, qf1, family);
Expand Down