Skip to content

Commit

Permalink
ignite-2.4.1-merge-master Fixing checkpoint lock acquisition
Browse files Browse the repository at this point in the history
  • Loading branch information
agoncharuk committed Dec 19, 2017
1 parent 7f9ae3f commit b00be67
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4458,6 +4458,8 @@ private boolean clearLocally0(K key, boolean readers) {

GridCacheVersion obsoleteVer = ctx.versions().next();

ctx.shared().database().checkpointReadLock();

try {
KeyCacheObject cacheKey = ctx.toCacheKeyObject(key);

Expand All @@ -4472,6 +4474,9 @@ private boolean clearLocally0(K key, boolean readers) {
catch (IgniteCheckedException ex) {
U.error(log, "Failed to clearLocally entry for key: " + key, ex);
}
finally {
ctx.shared().database().checkpointReadUnlock();
}

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1949,15 +1949,21 @@ public void applyUpdatesOnRecovery(

for (DataEntry dataEntry : dataRec.writeEntries()) {
if (entryPredicate.apply(dataEntry)) {
int cacheId = dataEntry.cacheId();
checkpointReadLock();

GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
try {
int cacheId = dataEntry.cacheId();

if (cacheCtx != null)
applyUpdate(cacheCtx, dataEntry);
else if (log != null)
log.warning("Cache (cacheId=" + cacheId + ") is not started, can't apply updates.");
GridCacheContext cacheCtx = cctx.cacheContext(cacheId);

if (cacheCtx != null)
applyUpdate(cacheCtx, dataEntry);
else if (log != null)
log.warning("Cache (cacheId=" + cacheId + ") is not started, can't apply updates.");
}
finally {
checkpointReadUnlock();
}
}
}

Expand Down Expand Up @@ -2090,44 +2096,51 @@ private void restorePartitionState(
// TODO: https://issues.apache.org/jira/browse/IGNITE-6097
grp.offheap().onPartitionInitialCounterUpdated(i, 0);

long partMetaId = pageMem.partitionMetaPageId(grpId, i);
long partMetaPage = pageMem.acquirePage(grpId, partMetaId);
checkpointReadLock();

try {
long pageAddr = pageMem.writeLock(grpId, partMetaId, partMetaPage);

boolean changed = false;
long partMetaId = pageMem.partitionMetaPageId(grpId, i);
long partMetaPage = pageMem.acquirePage(grpId, partMetaId);

try {
PagePartitionMetaIO io = PagePartitionMetaIO.VERSIONS.forPage(pageAddr);
long pageAddr = pageMem.writeLock(grpId, partMetaId, partMetaPage);

if (restore != null) {
int stateId = restore.get1();
boolean changed = false;

io.setPartitionState(pageAddr, (byte)stateId);
try {
PagePartitionMetaIO io = PagePartitionMetaIO.VERSIONS.forPage(pageAddr);

if (restore != null) {
int stateId = restore.get1();

io.setPartitionState(pageAddr, (byte)stateId);

changed = updateState(part, stateId);
changed = updateState(part, stateId);

if (stateId == GridDhtPartitionState.MOVING.ordinal() ||
stateId == GridDhtPartitionState.OWNING.ordinal()) {
if (stateId == GridDhtPartitionState.MOVING.ordinal() ||
stateId == GridDhtPartitionState.OWNING.ordinal()) {

if (part.initialUpdateCounter() < restore.get2() ||
stateId == GridDhtPartitionState.MOVING.ordinal()) {
part.initialUpdateCounter(restore.get2());
if (part.initialUpdateCounter() < restore.get2() ||
stateId == GridDhtPartitionState.MOVING.ordinal()) {
part.initialUpdateCounter(restore.get2());

changed = true;
changed = true;
}
}
}
else
changed = updateState(part, (int)io.getPartitionState(pageAddr));
}
finally {
pageMem.writeUnlock(grpId, partMetaId, partMetaPage, null, changed);
}
else
changed = updateState(part, (int)io.getPartitionState(pageAddr));
}
finally {
pageMem.writeUnlock(grpId, partMetaId, partMetaPage, null, changed);
pageMem.releasePage(grpId, partMetaId, partMetaPage);
}
}
finally {
pageMem.releasePage(grpId, partMetaId, partMetaPage);
checkpointReadUnlock();
}
}
else if (restore != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1112,12 +1112,20 @@ public void testMetastorageWalRestore() throws Exception {

GridCacheSharedContext<Object, Object> sharedCtx0 = ignite0.context().cache().context();

MetaStorage storage = ((GridCacheDatabaseSharedManager)sharedCtx0.database()).metaStorage();
MetaStorage storage = sharedCtx0.database().metaStorage();

assert storage != null;

for (int i = 0; i < cnt; i++)
storage.putData(String.valueOf(i), new byte[] {1, 2, 3});
for (int i = 0; i < cnt; i++) {
sharedCtx0.database().checkpointReadLock();

try {
storage.putData(String.valueOf(i), new byte[]{1, 2, 3});
}
finally {
sharedCtx0.database().checkpointReadUnlock();
}
}

for (int i = 0; i < cnt; i++) {
byte[] value = storage.getData(String.valueOf(i));
Expand All @@ -1127,13 +1135,13 @@ public void testMetastorageWalRestore() throws Exception {

stopGrid(0);

ignite0 = (IgniteEx)startGrid(0);
ignite0 = startGrid(0);

ignite0.active(true);

sharedCtx0 = ignite0.context().cache().context();

storage = ((GridCacheDatabaseSharedManager)sharedCtx0.database()).metaStorage();
storage = sharedCtx0.database().metaStorage();

assert storage != null;

Expand Down

0 comments on commit b00be67

Please sign in to comment.