Skip to content

Commit

Permalink
IGNITE-24130 Move binaryMetadata, marshaller directories logic to Nod…
Browse files Browse the repository at this point in the history
…eFileTree (apache#11840)
  • Loading branch information
nizhikov authored Feb 3, 2025
1 parent 29d21b2 commit 607b587
Show file tree
Hide file tree
Showing 48 changed files with 794 additions and 410 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@
import org.apache.ignite.configuration.DataStorageConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.WALMode;
import org.apache.ignite.internal.processors.cache.persistence.filename.SharedFileTree;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.G;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
import org.openjdk.jol.info.GraphLayout;

import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.DFLT_STORE_DIR;

/**
*
*/
Expand Down Expand Up @@ -68,10 +67,12 @@ private void cleanPersistenceDir() throws Exception {
if (!F.isEmpty(G.allGrids()))
throw new IgniteException("Grids are not stopped");

SharedFileTree sft = new SharedFileTree(U.defaultWorkDirectory());

U.delete(U.resolveWorkDirectory(U.defaultWorkDirectory(), "cp", false));
U.delete(U.resolveWorkDirectory(U.defaultWorkDirectory(), DFLT_STORE_DIR, false));
U.delete(U.resolveWorkDirectory(U.defaultWorkDirectory(), "marshaller", false));
U.delete(U.resolveWorkDirectory(U.defaultWorkDirectory(), "binary_meta", false));
U.delete(sft.db());
U.delete(sft.marshaller());
U.delete(sft.binaryMetaRoot());
}

/** */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.ignite.cache.QueryEntity;
import org.apache.ignite.cache.query.annotations.QuerySqlField;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.DataStorageConfiguration;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.U;
Expand Down Expand Up @@ -144,16 +143,7 @@ protected String getCfgUrl() {
assertTrue(conn.isClosed());
}

cleanUpWorkingDir();
}

/**
* Clean up working directory.
*/
private void cleanUpWorkingDir() throws Exception {
String workDir = U.defaultWorkDirectory();

U.delete(U.resolveWorkDirectory(workDir, DataStorageConfiguration.DFLT_MARSHALLER_PATH, false));
U.delete(sharedFileTree().marshaller());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.compatibility.testframework.junits.SkipTestIfIsJdkNewer;
import org.apache.ignite.configuration.DataStorageConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.MemoryConfiguration;
import org.apache.ignite.configuration.MemoryPolicyConfiguration;
import org.apache.ignite.configuration.PersistentStoreConfiguration;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.processors.cache.GridCacheAbstractFullApiSelfTest;
import org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree;
import org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderResolver;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteInClosure;
Expand Down Expand Up @@ -222,7 +222,10 @@ private void assertNodeIndexesInFolder(Integer... indexes) throws IgniteCheckedE
* @throws IgniteCheckedException if IO error occur
*/
private void assertPdsDirsDefaultExist(String subDirName) throws IgniteCheckedException {
assertDirectoryExist(DataStorageConfiguration.DFLT_BINARY_METADATA_PATH, subDirName);
NodeFileTree ft = nodeFileTree(subDirName);

assertTrue(ft.binaryMeta().exists() && ft.binaryMeta().isDirectory());

assertDirectoryExist(PersistentStoreConfiguration.DFLT_WAL_STORE_PATH, subDirName);
assertDirectoryExist(PersistentStoreConfiguration.DFLT_WAL_ARCHIVE_PATH, subDirName);
assertDirectoryExist(PdsFolderResolver.DB_DEFAULT_FOLDER, subDirName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
import org.apache.ignite.internal.util.typedef.internal.U;

import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.DFLT_STORE_DIR;
import static org.apache.ignite.internal.processors.cache.persistence.filename.SharedFileTree.BINARY_METADATA_DIR;
import static org.apache.ignite.internal.processors.cache.persistence.filename.SharedFileTree.MARSHALLER_DIR;

/**
* Super class for all persistence compatibility tests.
*/
public abstract class IgnitePersistenceCompatibilityAbstractTest extends IgniteCompatibilityAbstractTest {
/** Persistence directories. */
private static final List<String> PERSISTENCE_DIRS = Arrays.asList(DFLT_STORE_DIR, "binary_meta", "cp", "marshaller");
private static final List<String> PERSISTENCE_DIRS
= Arrays.asList(DFLT_STORE_DIR, BINARY_METADATA_DIR, "cp", MARSHALLER_DIR);

/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.apache.ignite.cache.QueryIndex;
import org.apache.ignite.cluster.ClusterState;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.DataStorageConfiguration;
import org.apache.ignite.configuration.DiskPageCompression;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.GridKernalContextImpl;
Expand Down Expand Up @@ -292,8 +291,8 @@ public void testRestoreNotCompressed_OnGridWithoutCompression() throws Exception

U.delete(U.resolveWorkDirectory(dir.toString(), "cp", false));
U.delete(U.resolveWorkDirectory(dir.toString(), DFLT_STORE_DIR, false));
U.delete(U.resolveWorkDirectory(dir.toString(), DataStorageConfiguration.DFLT_MARSHALLER_PATH, false));
U.delete(U.resolveWorkDirectory(dir.toString(), DataStorageConfiguration.DFLT_BINARY_METADATA_PATH, false));
U.delete(nodeFileTree(dir.toString()).marshaller());
U.delete(nodeFileTree(dir.toString()).binaryMetaRoot());
}
}
catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,6 @@ public class DataStorageConfiguration implements Serializable {
/** Default change data capture directory maximum size. */
public static final long DFLT_CDC_WAL_DIRECTORY_MAX_SIZE = 0;

/** Default path (relative to working directory) of binary metadata folder */
public static final String DFLT_BINARY_METADATA_PATH = "db/binary_meta";

/** Default path (relative to working directory) of marshaller mappings folder */
public static final String DFLT_MARSHALLER_PATH = "db/marshaller";

/** Default write throttling enabled. */
public static final boolean DFLT_WRITE_THROTTLING_ENABLED = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.apache.ignite.spi.encryption.EncryptionSpi;

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.apache.ignite.configuration.DataStorageConfiguration.DFLT_MARSHALLER_PATH;
import static org.apache.ignite.internal.IgniteKernal.NL;
import static org.apache.ignite.internal.IgniteKernal.SITE;
import static org.apache.ignite.internal.IgniteVersionUtils.ACK_VER_STR;
Expand Down Expand Up @@ -87,7 +86,7 @@ public DumpReader(DumpReaderConfiguration cfg, IgniteLogger log) {
cnsmr.start();

try {
File[] files = new File(cfg.dumpRoot(), DFLT_MARSHALLER_PATH).listFiles(BinaryUtils::notTmpFile);
File[] files = F.first(dump.fileTrees()).marshaller().listFiles(BinaryUtils::notTmpFile);

if (files != null)
cnsmr.onMappings(CdcMain.typeMappingIterator(files, tm -> true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.configuration.DataStorageConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap;
import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap;
import org.apache.ignite.internal.processors.cache.persistence.filename.SharedFileTree;
import org.apache.ignite.internal.processors.closure.GridClosureProcessor;
import org.apache.ignite.internal.processors.marshaller.MappedName;
import org.apache.ignite.internal.processors.marshaller.MappingExchangeResult;
Expand Down Expand Up @@ -192,8 +191,10 @@ public void onMappingDataReceived(IgniteLogger log, List<Map<Integer, MappedName
*/
public static void saveMappings(GridKernalContext ctx, List<Map<Integer, MappedName>> mappings, File dir)
throws IgniteCheckedException {
MarshallerMappingFileStore writer = new MarshallerMappingFileStore(ctx,
resolveMappingFileStoreWorkDir(dir.getAbsolutePath()));
MarshallerMappingFileStore writer = new MarshallerMappingFileStore(
ctx,
new SharedFileTree(dir).mkdirMarshaller()
);

addPlatformMappings(ctx.log(MarshallerContextImpl.class),
mappings,
Expand Down Expand Up @@ -583,17 +584,14 @@ private static void putAtIndex(
* @param transport Transport.
*/
public void onMarshallerProcessorStarted(
GridKernalContext ctx,
MarshallerMappingTransport transport
GridKernalContext ctx,
MarshallerMappingTransport transport
) throws IgniteCheckedException {
assert ctx != null;

IgniteConfiguration cfg = ctx.config();
String workDir = U.workDirectory(cfg.getWorkDirectory(), cfg.getIgniteHome());

fileStore = marshallerMappingFileStoreDir == null ?
new MarshallerMappingFileStore(ctx, resolveMappingFileStoreWorkDir(workDir)) :
new MarshallerMappingFileStore(ctx, marshallerMappingFileStoreDir);
fileStore = marshallerMappingFileStoreDir == null
? new MarshallerMappingFileStore(ctx, ctx.pdsFolderResolver().fileTree().mkdirMarshaller())
: new MarshallerMappingFileStore(ctx, marshallerMappingFileStoreDir);
this.transport = transport;
closProc = ctx.closure();
clientNode = ctx.clientNode();
Expand All @@ -604,30 +602,6 @@ public void onMarshallerProcessorStarted(
MarshallerUtils.setNodeName(jdkMarsh, ctx.igniteInstanceName());
}

/**
* @param igniteWorkDir Base ignite working directory.
* @return Resolved directory.
*/
public static File resolveMappingFileStoreWorkDir(String igniteWorkDir) {
File dir = mappingFileStoreWorkDir(igniteWorkDir);

if (!U.mkdirs(dir))
throw new IgniteException("Could not create directory for marshaller mappings: " + dir);

return dir;
}

/**
* @param igniteWorkDir Base ignite working directory.
* @return Work directory for marshaller mappings.
*/
public static File mappingFileStoreWorkDir(String igniteWorkDir) {
if (F.isEmpty(igniteWorkDir))
throw new IgniteException("Work directory has not been set: " + igniteWorkDir);

return new File(igniteWorkDir, DataStorageConfiguration.DFLT_MARSHALLER_PATH);
}

/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.internal.binary.BinaryUtils;
import org.apache.ignite.internal.processors.cache.persistence.filename.SharedFileTree;
import org.apache.ignite.internal.util.GridStripedLock;
import org.apache.ignite.internal.util.IgniteUtils;
import org.apache.ignite.internal.util.typedef.internal.U;
Expand Down Expand Up @@ -223,7 +224,7 @@ private void fixLegacyFolder() throws IgniteCheckedException {

File legacyDir = new File(
ctx.config().getWorkDirectory(),
"marshaller"
SharedFileTree.MARSHALLER_DIR
);

File legacyTmpDir = new File(legacyDir + TMP_SUFFIX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.GridLoggerProxy;
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
import org.apache.ignite.internal.MarshallerContextImpl;
import org.apache.ignite.internal.binary.BinaryUtils;
import org.apache.ignite.internal.cdc.WalRecordsConsumer.DataEntryIterator;
import org.apache.ignite.internal.pagemem.wal.WALIterator;
import org.apache.ignite.internal.pagemem.wal.record.CdcManagerRecord;
import org.apache.ignite.internal.pagemem.wal.record.DataRecord;
import org.apache.ignite.internal.pagemem.wal.record.WALRecord;
import org.apache.ignite.internal.processors.cache.GridLocalConfigManager;
import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
import org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree;
import org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderResolver;
import org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings;
import org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager;
Expand Down Expand Up @@ -233,11 +232,8 @@ public class CdcMain implements Runnable {
/** Database directory. */
private File dbDir;

/** Binary meta directory. */
private File binaryMeta;

/** Marshaller directory. */
private File marshaller;
/** Ignite folders. */
private NodeFileTree ft;

/** Standalone kernal context. */
private StandaloneGridKernalContext kctx;
Expand Down Expand Up @@ -329,21 +325,15 @@ public void runX() throws Exception {
}

try (CdcFileLockHolder lock = lockPds()) {
String consIdDir = cdcDir.getName(cdcDir.getNameCount() - 1).toString();

Files.createDirectories(cdcDir.resolve(STATE_DIR));

binaryMeta = CacheObjectBinaryProcessorImpl.binaryWorkDir(igniteCfg.getWorkDirectory(), consIdDir);

marshaller = MarshallerContextImpl.mappingFileStoreWorkDir(igniteCfg.getWorkDirectory());

if (log.isInfoEnabled()) {
log.info("Change Data Capture [dir=" + cdcDir + ']');
log.info("Ignite node Binary meta [dir=" + binaryMeta + ']');
log.info("Ignite node Marshaller [dir=" + marshaller + ']');
log.info("Ignite node Binary meta [dir=" + ft.binaryMeta() + ']');
log.info("Ignite node Marshaller [dir=" + ft.marshaller() + ']');
}

kctx = startStandaloneKernal();
startStandaloneKernal();

initMetrics();

Expand Down Expand Up @@ -392,8 +382,8 @@ protected CdcConsumerState createState(Path stateDir) {
* @return Kernal instance.
* @throws IgniteCheckedException If failed.
*/
private StandaloneGridKernalContext startStandaloneKernal() throws IgniteCheckedException {
StandaloneGridKernalContext kctx = new StandaloneGridKernalContext(log, binaryMeta, marshaller) {
private void startStandaloneKernal() throws IgniteCheckedException {
kctx = new StandaloneGridKernalContext(log, ft.binaryMeta(), ft.marshaller()) {
@Override protected IgniteConfiguration prepareIgniteConfiguration() {
IgniteConfiguration cfg = super.prepareIgniteConfiguration();

Expand Down Expand Up @@ -428,14 +418,12 @@ private StandaloneGridKernalContext startStandaloneKernal() throws IgniteChecked
}

mreg = kctx.metric().registry("cdc");

return kctx;
}

/** Initialize metrics. */
private void initMetrics() {
mreg.objectMetric(BINARY_META_DIR, String.class, "Binary meta directory").value(binaryMeta.getAbsolutePath());
mreg.objectMetric(MARSHALLER_DIR, String.class, "Marshaller directory").value(marshaller.getAbsolutePath());
mreg.objectMetric(BINARY_META_DIR, String.class, "Binary meta directory").value(ft.binaryMeta().getAbsolutePath());
mreg.objectMetric(MARSHALLER_DIR, String.class, "Marshaller directory").value(ft.marshaller().getAbsolutePath());
mreg.objectMetric(CDC_DIR, String.class, "CDC directory").value(cdcDir.toFile().getAbsolutePath());

curSegmentIdx = mreg.longMetric(CUR_SEG_IDX, "Current segment index");
Expand Down Expand Up @@ -468,6 +456,8 @@ private CdcFileLockHolder lockPds() throws IgniteCheckedException {
"[workDir=" + igniteCfg.getWorkDirectory() + ", consistentId=" + igniteCfg.getConsistentId() + ']');
}

ft = new NodeFileTree(igniteCfg, settings.folderName());

CdcFileLockHolder lock = settings.getLockedFileLockHolder();

if (lock == null) {
Expand Down Expand Up @@ -567,8 +557,8 @@ private boolean consumeSegment(Path segment) {
IgniteWalIteratorFactory.IteratorParametersBuilder builder =
new IgniteWalIteratorFactory.IteratorParametersBuilder()
.log(log)
.binaryMetadataFileStoreDir(binaryMeta)
.marshallerMappingFileStoreDir(marshaller)
.binaryMetadataFileStoreDir(ft.binaryMeta())
.marshallerMappingFileStoreDir(ft.marshaller())
.igniteConfigurationModifier((cfg) -> cfg.setPluginProviders(igniteCfg.getPluginProviders()))
.keepBinary(cdcCfg.isKeepBinary())
.filesOrDirs(segment.toFile());
Expand Down Expand Up @@ -692,7 +682,7 @@ private void updateMetadata() {
/** Search for new or changed {@link BinaryType} and notifies the consumer. */
private void updateTypes() {
try {
File[] files = binaryMeta.listFiles();
File[] files = ft.binaryMeta().listFiles();

if (files == null)
return;
Expand All @@ -710,7 +700,7 @@ private void updateTypes() {
typesState.put(typeId, lastModified);

try {
kctx.cacheObjects().cacheMetadataLocally(binaryMeta, typeId);
kctx.cacheObjects().cacheMetadataLocally(ft.binaryMeta(), typeId);
}
catch (IgniteCheckedException e) {
throw new IgniteException(e);
Expand Down Expand Up @@ -739,7 +729,7 @@ private void updateTypes() {
/** Search for new or changed {@link TypeMapping} and notifies the consumer. */
private void updateMappings() {
try {
File[] files = marshaller.listFiles(BinaryUtils::notTmpFile);
File[] files = ft.marshaller().listFiles(BinaryUtils::notTmpFile);

if (files == null)
return;
Expand Down
Loading

0 comments on commit 607b587

Please sign in to comment.