Skip to content

Commit

Permalink
IGNITE-20507 Fixed StoredCacheData removing when a node filter is set (
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladsz83 authored Oct 5, 2023
1 parent 6f5e27e commit 0e97810
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_INVALID_ARGUMENTS;
import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK;
import static org.apache.ignite.internal.management.api.CommandUtils.INDENT;
import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.DFLT_STORE_DIR;
import static org.apache.ignite.internal.util.IgniteUtils.max;
import static org.apache.ignite.testframework.GridTestUtils.assertContains;
import static org.apache.ignite.testframework.GridTestUtils.getFieldValue;
Expand Down Expand Up @@ -239,13 +238,6 @@ public void testWithNodeFilter() throws Exception {
grid(LAST_NODE_NUM).destroyCache("cacheWithNodeFilter");

awaitPartitionMapExchange();

// TODO Remove after IGNITE-20507.
// Cleaning cache meta being kept.
for (Ignite ig : G.allGrids()) {
U.delete(U.resolveWorkDirectory(U.defaultWorkDirectory(), DFLT_STORE_DIR + '/' + ig.name()
+ "/cache-cacheWithNodeFilter", false));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1773,6 +1773,21 @@ public void cleanupRemovedCacheGroups(AffinityTopologyVersion topVer) {
return null;
}

/**
* @param cacheName Cache name.
*/
public @Nullable DynamicCacheDescriptor markedForDeletionCache(String cacheName) {
// Find the "earliest" available descriptor.
for (Map<String, DynamicCacheDescriptor> descriptors : markedForDeletionCaches.values()) {
DynamicCacheDescriptor desc = descriptors.get(cacheName);

if (desc != null)
return desc;
}

return null;
}

/**
* Save dynamic cache descriptor on disk.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,15 +1086,8 @@ private void stopCache(GridCacheAdapter<?, ?> cache, boolean cancel, boolean cal

U.stopLifecycleAware(log, lifecycleAwares(ctx.group(), cache.configuration(), ctx.store().configuredStore()));

if (callDestroy && CU.storeCacheConfig(sharedCtx, ctx.config())) {
try {
locCfgMgr.removeCacheData(new StoredCacheData(ctx.config()));
}
catch (IgniteCheckedException e) {
U.error(log, "Failed to delete cache configuration data while destroying cache" +
"[cache=" + ctx.name() + "]", e);
}
}
if (callDestroy)
removeCacheConfig(ctx.config());

if (log.isInfoEnabled()) {
if (ctx.group().sharedGroup())
Expand All @@ -1108,6 +1101,19 @@ private void stopCache(GridCacheAdapter<?, ?> cache, boolean cancel, boolean cal
}
}

/** */
private void removeCacheConfig(CacheConfiguration<?, ?> cacheCfg) {
if (CU.storeCacheConfig(sharedCtx, cacheCfg)) {
try {
locCfgMgr.removeCacheData(new StoredCacheData(cacheCfg));
}
catch (IgniteCheckedException e) {
U.error(log, "Failed to delete cache configuration data while destroying cache" +
"[cache=" + cacheCfg.getName() + "]", e);
}
}
}

/**
* @param cache Cache.
* @throws IgniteCheckedException If failed.
Expand Down Expand Up @@ -2607,9 +2613,16 @@ public void prepareCacheStop(String cacheName, boolean callDestroy, boolean clea

stopCache(cache, true, callDestroy, clearCache, clearDbObjects);
}
else
else {
// Try to unregister query structures for not started caches.
ctx.query().onCacheStop(cacheName);

// Cache adapter may not exist due to the node filter.
DynamicCacheDescriptor cacheToDelete = callDestroy ? cachesInfo.markedForDeletionCache(cacheName) : null;

if (cacheToDelete != null)
removeCacheConfig(cacheToDelete.cacheConfiguration());
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,29 +334,6 @@ public static boolean cheatCache(int id) {
}
};

/** Transaction entry to key. */
private static final IgniteClosure tx2key = new C1<IgniteTxEntry, Object>() {
@Override public Object apply(IgniteTxEntry e) {
return e.key();
}

@Override public String toString() {
return "Cache transaction entry to key converter.";
}
};

/** Transaction entry to key. */
private static final IgniteClosure txCol2key = new C1<Collection<IgniteTxEntry>, Collection<Object>>() {
@SuppressWarnings( {"unchecked"})
@Override public Collection<Object> apply(Collection<IgniteTxEntry> e) {
return F.viewReadOnly(e, tx2key);
}

@Override public String toString() {
return "Cache transaction entry collection to key collection converter.";
}
};

/** Converts transaction to XID version. */
private static final IgniteClosure tx2xidVer = new C1<IgniteInternalTx, GridCacheVersion>() {
@Override public GridCacheVersion apply(IgniteInternalTx tx) {
Expand All @@ -368,13 +345,6 @@ public static boolean cheatCache(int id) {
}
};

/** Converts tx entry to entry. */
private static final IgniteClosure tx2entry = new C1<IgniteTxEntry, GridCacheEntryEx>() {
@Override public GridCacheEntryEx apply(IgniteTxEntry e) {
return e.cached();
}
};

/** Transaction entry to key. */
private static final IgniteClosure entry2key = new C1<GridCacheEntryEx, KeyCacheObject>() {
@Override public KeyCacheObject apply(GridCacheEntryEx e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,4 @@ public static void zeroMemory(ByteBuffer buf, int off, int len) {
public static void copyMemory(long srcAddr, long srcOff, long dstAddr, long dstOff, long cnt) {
GridUnsafe.copyMemory(null, srcAddr + srcOff, null, dstAddr + dstOff, cnt);
}

/**
* @param addr Address.
* @param off Offset.
* @param len Length.
*/
public static void zeroMemory(long addr, int off, int len) {
GridUnsafe.zeroMemory(addr + off, len);
}
}
Loading

0 comments on commit 0e97810

Please sign in to comment.