You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2023/01/13 10:40:48 UTC

[GitHub] [cassandra] jacek-lewandowski commented on a diff in pull request #2081: Fixes ordering in StandaloneUpgrader

jacek-lewandowski commented on code in PR #2081:
URL: https://github.com/apache/cassandra/pull/2081#discussion_r1069226909


##########
test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java:
##########
@@ -686,4 +689,77 @@ private static void copyFile(File cfDir, File file) throws IOException
                 }
         }
     }
+
+    /**
+     * Finds the first point at which the HashSet inserts a generation before a previous
+     * generation in the set. This is used in testing to verfy the sequence of tables where
+     * the generation order is significant.
+     * @param legacyVersion the legacy version to work with.
+     * @return the generation that causes of the inversion.
+     */
+    public static int findInversion(String legacyVersion) {
+        String ksname = "legacy_tables";
+        String cfname = String.format("legacy_%s_multiple", legacyVersion);;
+        SSTableFormat.Type formatType = SSTableFormat.Type.BIG;
+        int generation = 0;
+        SequenceBasedSSTableId id = new SequenceBasedSSTableId(generation);
+        File directory = new File( System.getProperty("java.io.tmpdir"));
+        Version version = formatType.info.getVersion(legacyVersion);
+        Descriptor descriptor = new Descriptor( version,  directory,  ksname,  cfname, id, formatType);
+        HashSet<Descriptor> set = new HashSet<>();
+        set.add( descriptor );
+        Object[] arry = set.toArray();
+        do
+        {
+            id = new SequenceBasedSSTableId(++generation);
+            descriptor = new Descriptor(version , directory , ksname , cfname , id , formatType);
+            set.add(descriptor);
+            arry = set.toArray();
+        }  while( descriptor.equals(arry[arry.length-1]));
+        return generation;
+    }
+
+    /**
+     * Generates 3 sstables generations in legacy_x_multiple and adds it to the column store.
+     * Tables are guaranteed to not be returned in generation order when iterated via the
+     * {@code Directories.SSTableLister} class.
+     * @param legacyVersion the version to create tables for
+     * @throws IOException on IO error.
+     */
+    public static int generateMultipleTables(String legacyVersion) throws IOException {
+
+        int start = findInversion(legacyVersion) - 1;
+        String tableName = String.format( "legacy_%s_multiple", legacyVersion);
+
+        File sourceDir = getTableDir(legacyVersion, String.format( "legacy_%s_simple", legacyVersion));
+
+        logger.info("creating legacy table {}", tableName);
+
+        QueryProcessor.executeInternal(String.format("CREATE TABLE legacy_tables.%s (pk text PRIMARY KEY, val text)", tableName));
+        ColumnFamilyStore cfs = Keyspace.open("legacy_tables").getColumnFamilyStore(tableName);
+
+        List<File> cfDirs = cfs.getDirectories().getCFDirectories();
+        File cfDir = cfDirs.get(0);
+
+        for (int i=0;i<3;i++) {
+            for (File file : sourceDir.tryList())
+            {
+                byte[] buf = new byte[65536];
+                if (file.isFile())
+                {
+                    String[] fileNameParts = file.name().split("-");
+                    String targetName = String.format( "%s-%s-%s-%s", legacyVersion, start+i, fileNameParts[2], fileNameParts[3]);
+                    logger.info("creating legacy sstable {}", targetName);
+                    File target = new File(cfDir, targetName);
+                    int rd;
+                    try (FileInputStreamPlus is = new FileInputStreamPlus(file);

Review Comment:
   I believe there is some `FileUtils.copy` method



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org