Skip to content

Commit

Permalink
IGNITE-9455 Total allocated size memory metric is always zero for met…
Browse files Browse the repository at this point in the history
…astore data region - Fixes #5195.

Signed-off-by: Aleksey Plekhanov <Plehanov.Alex@gmail.com>
  • Loading branch information
xtern authored and alex-plekhanov committed Dec 7, 2018
1 parent 472889d commit 137a0e7
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 33 deletions.
Expand Up @@ -130,7 +130,6 @@
import org.apache.ignite.internal.processors.cache.mvcc.MvccProcessorImpl;
import org.apache.ignite.internal.processors.cache.persistence.DataRegion;
import org.apache.ignite.internal.processors.cache.persistence.DataStorageMXBeanImpl;
import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager;
import org.apache.ignite.internal.processors.cache.persistence.filename.PdsConsistentIdProcessor;
import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
import org.apache.ignite.internal.processors.closure.GridClosureProcessor;
Expand Down Expand Up @@ -2109,12 +2108,7 @@ private void ackNodeMetrics(DecimalFormat dblFmt,

pdsUsedSummary += pdsUsed;

// TODO https://issues.apache.org/jira/browse/IGNITE-9455
// TODO Print actual value for meta store region when issue will be fixed.
boolean metastore =
GridCacheDatabaseSharedManager.METASTORE_DATA_REGION_NAME.equals(region.config().getName());

String pdsUsedSize = metastore ? "unknown" : dblFmt.format(pdsUsedMBytes) + "MB";
String pdsUsedSize = dblFmt.format(pdsUsedMBytes) + "MB";

pdsRegionsInfo.append(" ^-- ")
.append(region.config().getName()).append(" region")
Expand Down
Expand Up @@ -85,6 +85,13 @@ public GroupAllocationTracker(AllocatedPageTracker delegate) {

delegate.updateTotalAllocatedPages(delta);
}

/**
* Resets count of allocated pages to zero.
*/
public void reset() {
totalAllocatedPages.reset();
}
}

/**
Expand Down
Expand Up @@ -480,4 +480,23 @@ public void subIntervals(int subInts) {
pageReplaceRate = new HitRateMetrics((int)rateTimeInterval, subInts);
pageReplaceAge = new HitRateMetrics((int)rateTimeInterval, subInts);
}

/**
* Clear metrics.
*/
public void clear() {
totalAllocatedPages.reset();
grpAllocationTrackers.values().forEach(GroupAllocationTracker::reset);
largeEntriesPages.reset();
dirtyPages.reset();
readPages.reset();
writtenPages.reset();
replacedPages.reset();
offHeapSize.set(0);
checkpointBufferSize.set(0);
allocRate.clear();
evictRate.clear();
pageReplaceRate.clear();
pageReplaceAge.clear();
}
}
Expand Up @@ -61,7 +61,9 @@
import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter;
import org.apache.ignite.internal.processors.cache.StoredCacheData;
import org.apache.ignite.internal.processors.cache.persistence.AllocatedPageTracker;
import org.apache.ignite.internal.processors.cache.persistence.DataRegion;
import org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl;
import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager;
import org.apache.ignite.internal.processors.cache.persistence.StorageException;
import org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings;
import org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage;
Expand Down Expand Up @@ -368,11 +370,13 @@ public FilePageStoreManager(GridKernalContext ctx) {
int grpId = MetaStorage.METASTORAGE_CACHE_ID;

if (!idxCacheStores.containsKey(grpId)) {
DataRegion dataRegion = cctx.database().dataRegion(GridCacheDatabaseSharedManager.METASTORE_DATA_REGION_NAME);

CacheStoreHolder holder = initDir(
new File(storeWorkDir, META_STORAGE_NAME),
grpId,
1,
AllocatedPageTracker.NO_OP,
dataRegion.memoryMetrics(),
false);

CacheStoreHolder old = idxCacheStores.put(grpId, holder);
Expand Down
Expand Up @@ -139,6 +139,8 @@ public MetaStorage(

/** */
public void init(IgniteCacheDatabaseSharedManager db) throws IgniteCheckedException {
regionMetrics.clear();

getOrAllocateMetas();

if (!empty) {
Expand Down
Expand Up @@ -32,9 +32,6 @@
* Check logging local node metrics with PDS enabled.
*/
public class GridNodeMetricsLogPdsSelfTest extends GridNodeMetricsLogSelfTest {
/** */
private static final String UNKNOWN_SIZE = "unknown";

/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
Expand Down Expand Up @@ -85,7 +82,7 @@ public class GridNodeMetricsLogPdsSelfTest extends GridNodeMetricsLogSelfTest {
Set<String> regions = new HashSet<>();

Pattern ptrn = Pattern.compile("(?m).{2,}( {3}(?<name>.+) region|Ignite persistence) " +
"\\[used=(?<used>[-.\\d]+|" + UNKNOWN_SIZE + ")?.*]");
"\\[used=(?<used>[-.\\d]+)?.*]");

Matcher matcher = ptrn.matcher(logOutput);

Expand All @@ -96,9 +93,7 @@ public class GridNodeMetricsLogPdsSelfTest extends GridNodeMetricsLogSelfTest {

String usedSize = matcher.group("used");

// TODO https://issues.apache.org/jira/browse/IGNITE-9455
// TODO The actual value of the metric should be printed when this issue is solved.
int used = UNKNOWN_SIZE.equals(usedSize) ? 0 : Integer.parseInt(usedSize);
int used = Integer.parseInt(usedSize);

assertTrue(used + " should be non negative: " + subj, used >= 0);

Expand Down
Expand Up @@ -36,6 +36,7 @@
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.pagemem.PageIdAllocator;
import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
import org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl;
import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager;
import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore;
Expand All @@ -51,6 +52,10 @@

import static java.nio.file.Files.newDirectoryStream;
import static org.apache.ignite.configuration.DataStorageConfiguration.DFLT_DATA_REG_DEFAULT_NAME;
import static org.apache.ignite.internal.processors.cache.GridCacheUtils.UTILITY_CACHE_NAME;
import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.META_STORAGE_NAME;
import static org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage.METASTORAGE_CACHE_ID;
import static org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage.METASTORAGE_CACHE_NAME;

/**
*
Expand Down Expand Up @@ -150,7 +155,7 @@ public void testMemoryUsageSingleNode() throws Exception {

forceCheckpoint();

checkMetricsConsistency(node, DEFAULT_CACHE_NAME);
checkMetricsConsistency(node);
}

currMetrics = getDfltRegionMetrics(node);
Expand Down Expand Up @@ -183,8 +188,8 @@ public void testMemoryUsageMultipleNodes() throws Exception {

forceCheckpoint();

checkMetricsConsistency(node0, DEFAULT_CACHE_NAME);
checkMetricsConsistency(node1, DEFAULT_CACHE_NAME);
checkMetricsConsistency(node0);
checkMetricsConsistency(node1);

IgniteEx node2 = startGrid(2);

Expand All @@ -194,9 +199,9 @@ public void testMemoryUsageMultipleNodes() throws Exception {

forceCheckpoint();

checkMetricsConsistency(node0, DEFAULT_CACHE_NAME);
checkMetricsConsistency(node1, DEFAULT_CACHE_NAME);
checkMetricsConsistency(node2, DEFAULT_CACHE_NAME);
checkMetricsConsistency(node0);
checkMetricsConsistency(node1);
checkMetricsConsistency(node2);

stopGrid(1, true);

Expand All @@ -206,8 +211,8 @@ public void testMemoryUsageMultipleNodes() throws Exception {

forceCheckpoint();

checkMetricsConsistency(node0, DEFAULT_CACHE_NAME);
checkMetricsConsistency(node2, DEFAULT_CACHE_NAME);
checkMetricsConsistency(node0);
checkMetricsConsistency(node2);
}

/**
Expand Down Expand Up @@ -292,15 +297,23 @@ private static DataRegionMetrics getDfltRegionMetrics(Ignite node) {
throw new RuntimeException("No metrics found for default data region");
}

/** */
private void checkMetricsConsistency(final IgniteEx node) throws Exception {
checkMetricsConsistency(node, DEFAULT_CACHE_NAME);
checkMetricsConsistency(node, UTILITY_CACHE_NAME);
checkMetricsConsistency(node, METASTORAGE_CACHE_NAME);
}

/** */
private void checkMetricsConsistency(final IgniteEx node, String cacheName) throws Exception {
FilePageStoreManager pageStoreMgr = (FilePageStoreManager)node.context().cache().context().pageStore();

assert pageStoreMgr != null : "Persistence is not enabled";

File cacheWorkDir = pageStoreMgr.cacheWorkDir(
node.getOrCreateCache(cacheName).getConfiguration(CacheConfiguration.class)
);
boolean metaStore = METASTORAGE_CACHE_NAME.equals(cacheName);

File cacheWorkDir = metaStore ? new File(pageStoreMgr.workDir(), META_STORAGE_NAME) :
pageStoreMgr.cacheWorkDir(node.cachex(cacheName).configuration());

long totalPersistenceSize = 0;

Expand All @@ -310,7 +323,8 @@ private void checkMetricsConsistency(final IgniteEx node, String cacheName) thro
for (Path path : files) {
File file = path.toFile();

FilePageStore store = (FilePageStore)pageStoreMgr.getStore(CU.cacheId(cacheName), partId(file));
FilePageStore store = (FilePageStore)pageStoreMgr.getStore(metaStore ?
METASTORAGE_CACHE_ID : CU.cacheId(cacheName), partId(file));

int pageSize = store.getPageSize();
long storeSize = path.toFile().length() - store.headerSize();
Expand All @@ -322,12 +336,12 @@ private void checkMetricsConsistency(final IgniteEx node, String cacheName) thro
}
}

long totalAllocatedPagesFromMetrics = node.context().cache().context()
.cacheContext(CU.cacheId(DEFAULT_CACHE_NAME))
.group()
.dataRegion()
.memoryMetrics()
.getTotalAllocatedPages();
GridCacheSharedContext cctx = node.context().cache().context();

String regionName = metaStore ? GridCacheDatabaseSharedManager.METASTORE_DATA_REGION_NAME :
cctx.cacheContext(CU.cacheId(cacheName)).group().dataRegion().config().getName();

long totalAllocatedPagesFromMetrics = cctx.database().memoryMetrics(regionName).getTotalAllocatedPages();

assertEquals("Number of allocated pages is different than in metrics for [node=" + node.name() + ", cache=" + cacheName + "]",
totalPersistenceSize / pageStoreMgr.pageSize(), totalAllocatedPagesFromMetrics);
Expand Down

0 comments on commit 137a0e7

Please sign in to comment.