Skip to content

Commit

Permalink
IGNITE-8735 Metastorage creates its own index partition - Fixes apach…
Browse files Browse the repository at this point in the history
…e#5383.

Signed-off-by: Ivan Rakov <irakov@apache.org>
(cherry picked from commit a74d9c4)
  • Loading branch information
SpiderRus authored and antonovsergey93 committed Nov 15, 2018
1 parent 1262faa commit c1244cc
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
Expand Up @@ -35,6 +35,9 @@ public interface PageIdAllocator {
/** Special partition reserved for index space. */
public static final int INDEX_PARTITION = 0xFFFF;

/** Special partition reserved for metastore space. */
public static final int METASTORE_PARTITION = 0x0;

/**
* Allocates a page from the space for the given partition ID and the given flags.
*
Expand Down
Expand Up @@ -28,6 +28,7 @@
import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.internal.pagemem.FullPageId;
import org.apache.ignite.internal.pagemem.PageIdAllocator;
import org.apache.ignite.internal.pagemem.PageIdUtils;
import org.apache.ignite.internal.pagemem.PageMemory;
import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager;
Expand Down Expand Up @@ -62,6 +63,7 @@
import org.apache.ignite.marshaller.jdk.JdkMarshaller;
import org.jetbrains.annotations.NotNull;

import static org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_DATA;
import static org.apache.ignite.internal.pagemem.PageIdUtils.itemId;
import static org.apache.ignite.internal.pagemem.PageIdUtils.pageId;

Expand Down Expand Up @@ -506,6 +508,11 @@ public static class FreeListImpl extends AbstractFreeList<MetastorageDataRow> {
return SimpleDataPageIO.VERSIONS;
}

/** {@inheritDoc} */
@Override protected long allocatePageNoReuse() throws IgniteCheckedException {
return pageMem.allocatePage(grpId, PageIdAllocator.METASTORE_PARTITION, FLAG_DATA);
}

/**
* Read row from data pages.
*/
Expand Down
Expand Up @@ -19,6 +19,7 @@

import java.util.concurrent.atomic.AtomicLong;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.internal.pagemem.PageIdAllocator;
import org.apache.ignite.internal.pagemem.PageMemory;
import org.apache.ignite.internal.pagemem.PageUtils;
import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager;
Expand All @@ -31,6 +32,9 @@
import org.apache.ignite.internal.processors.failure.FailureProcessor;
import org.jetbrains.annotations.Nullable;

import static org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_DATA;
import static org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX;

/**
*
*/
Expand Down Expand Up @@ -94,6 +98,11 @@ public MetastorageRowStore rowStore() {
return rowStore;
}

/** {@inheritDoc} */
@Override protected long allocatePageNoReuse() throws IgniteCheckedException {
return pageMem.allocatePage(grpId, PageIdAllocator.METASTORE_PARTITION, FLAG_DATA);
}

/**
*
*/
Expand Down
Expand Up @@ -17,6 +17,9 @@
package org.apache.ignite.internal.processors.cache.persistence.metastorage;

import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.configuration.DataRegionConfiguration;
Expand Down Expand Up @@ -78,6 +81,81 @@ public class IgniteMetaStorageBasicTest extends GridCommonAbstractTest {
cleanPersistenceDir();
}

/**
*
*/
public void testMetaStorageMassivePutFixed() throws Exception {
IgniteEx ig = startGrid(0);

ig.cluster().active(true);

IgniteCacheDatabaseSharedManager db = ig.context().cache().context().database();

MetaStorage metaStorage = db.metaStorage();

assertNotNull(metaStorage);

Random rnd = new Random();

db.checkpointReadLock();

int size;
try {
for (int i = 0; i < 10_000; i++) {
size = rnd.nextBoolean() ? 3500 : 2 * 3500;
String key = "TEST_KEY_" + (i % 1000);

byte[] arr = new byte[size];
rnd.nextBytes(arr);

metaStorage.remove(key);

metaStorage.putData(key, arr/*b.toString().getBytes()*/);
}
}
finally {
db.checkpointReadUnlock();
}
}

/**
*
*/
public void testMetaStorageMassivePutRandom() throws Exception {
IgniteEx ig = startGrid(0);

ig.cluster().active(true);

IgniteCacheDatabaseSharedManager db = ig.context().cache().context().database();

MetaStorage metaStorage = db.metaStorage();

assertNotNull(metaStorage);

Random rnd = new Random();

db.checkpointReadLock();

int size;
try {
for (int i = 0; i < 50_000; i++) {
size = 100 + rnd.nextInt(9000);

String key = "TEST_KEY_" + (i % 2_000);

byte[] arr = new byte[size];
rnd.nextBytes(arr);

metaStorage.remove(key);

metaStorage.putData(key, arr/*b.toString().getBytes()*/);
}
}
finally {
db.checkpointReadUnlock();
}
}

/**
* Verifies that MetaStorage after massive amounts of keys stored and updated keys restores its state successfully
* after restart.
Expand Down

0 comments on commit c1244cc

Please sign in to comment.