FewJuho commented on code in PR #200: URL: https://github.com/apache/ignite-teamcity-bot/pull/200#discussion_r2301635959
########## migrator/src/main/java/migrate/GridIntListMigrator.java: ########## @@ -0,0 +1,532 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package migrate; + +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.Ignition; +import org.apache.ignite.binary.BinaryObject; +import org.apache.ignite.binary.BinaryObjectBuilder; +import org.apache.ignite.cache.query.QueryCursor; +import org.apache.ignite.cache.query.ScanQuery; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.configuration.BinaryConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.cache.Cache; +import java.io.File; +import java.lang.reflect.Constructor; +import java.util.*; +import java.util.concurrent.atomic.AtomicLong; + +/** + * Offline migrator for TeamCity Bot Ignite persistence. + * <p> + * Recursively scans all entries in Ignite caches and replaces any occurrence of the legacy type + * org.apache.ignite.internal.util.GridIntList with the new type + * org.apache.ignite.tcbot.common.util.GridIntList, preserving the int[] payload. + * <p> + * Usage: + * export IGNITE_WORK_DIR=/abs/path/to/work_backup + * ./gradlew -p migrator run --args="--verbose --report 200" # dry run with verbose report + * ./gradlew -p migrator run --args="--apply --report 500" # apply to all caches + */ + +public final class GridIntListMigrator { + /** + * Logger. + */ + private static final Logger log = LoggerFactory.getLogger(GridIntListMigrator.class); + + /** + * Fully-qualified name of the legacy type to replace. + */ + private static final String OLD_KEYS_TYPE = "org.apache.ignite.internal.util.GridIntList"; + + /** + * Fully-qualified name of the new type. + */ + private static final String NEW_KEYS_TYPE = "org.apache.ignite.tcbot.common.util.GridIntList"; + + /** + * Scan page size. + */ + private static final int DEFAULT_PAGE_SIZE = 256; + + /** + * Recursion guard to prevent accidental cycles. + */ + private static final int MAX_DEPTH = 32; + + /** + * Default constructor. + */ + private GridIntListMigrator() { + } + + /** + * Boots a standalone Ignite node on the given work dir and executes migration. + */ + public static void main(String[] args) { + System.setProperty("java.net.preferIPv4Stack", "true"); + + Args a = Args.parse(args); + + if (a.workDir == null || a.workDir.isEmpty()) { + String wd = System.getProperty("IGNITE_WORK_DIR"); + + if (wd == null || wd.isEmpty()) + wd = System.getenv("IGNITE_WORK_DIR"); + + a.workDir = wd; + } + + if (a.workDir == null || a.workDir.isEmpty()) { + log.error("IGNITE_WORK_DIR is not set. Use --workDir or set system/env variable."); + + System.exit(2); + } + + File checkDir = new File(a.workDir); + + if (!checkDir.isDirectory()) { + log.error("IGNITE_WORK_DIR is not a directory: {}", checkDir.getAbsolutePath()); + + System.exit(2); + } + + IgniteConfiguration cfg = new IgniteConfiguration() + .setIgniteInstanceName("tcbot-migrator") + .setWorkDirectory(a.workDir); + + String consistentId = detectConsistentId(a.workDir); + + if (consistentId != null) { + cfg.setConsistentId(consistentId); + + log.info("Using consistentId={}", consistentId); + } + else + log.warn("Couldnt detect consistentId."); + + DataStorageConfiguration ds = new DataStorageConfiguration(); + ds.getDefaultDataRegionConfiguration().setPersistenceEnabled(true); + cfg.setDataStorageConfiguration(ds); + + BinaryConfiguration bcfg = new BinaryConfiguration(); + cfg.setBinaryConfiguration(bcfg); + + Ignition.setClientMode(false); + + try (Ignite ig = Ignition.start(cfg)) { + ig.cluster().state(ClusterState.ACTIVE); + + Collection<String> cacheNames = new ArrayList<>(ig.cacheNames()); Review Comment: Seems good to scan all caches to prevent cache data loss. There's CLI command --cache to specify caches' names to scan/apply if needed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org