Maxwell-Guo commented on code in PR #2846:
URL: https://github.com/apache/cassandra/pull/2846#discussion_r1373276946
##########
test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java:
##########
@@ -1116,6 +1117,78 @@ public void testFrozenSetTypeCustomOrdered() throws
Exception
assertEquals(0, filtered.size());
}
+ @Test
+ public void testWriteWithSorted() throws Exception
+ {
+ String schema = "CREATE TABLE " + qualifiedTable + " ("
+ + " k int PRIMARY KEY,"
+ + " v blob )";
+ CQLSSTableWriter writer = CQLSSTableWriter.builder()
+ .inDirectory(dataDir)
Review Comment:
code format
##########
test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java:
##########
@@ -1116,6 +1117,78 @@ public void testFrozenSetTypeCustomOrdered() throws
Exception
assertEquals(0, filtered.size());
}
+ @Test
+ public void testWriteWithSorted() throws Exception
+ {
+ String schema = "CREATE TABLE " + qualifiedTable + " ("
+ + " k int PRIMARY KEY,"
+ + " v blob )";
+ CQLSSTableWriter writer = CQLSSTableWriter.builder()
+ .inDirectory(dataDir)
+ .forTable(schema)
+ .using("INSERT INTO " + qualifiedTable +
+ " (k, v) VALUES (?, textAsBlob(?))" )
+ .sorted()
+ .build();
+ int rowCount = 10_000;
+ for (int i = 0; i < rowCount; i++)
+ {
+ writer.addRow(i, UUID.randomUUID().toString());
+ }
+ writer.close();
+ loadSSTables(dataDir, keyspace);
+
+ UntypedResultSet resultSet = QueryProcessor.executeInternal("SELECT *
FROM " + qualifiedTable);
+ assertEquals(rowCount, resultSet.size());
+ Iterator<UntypedResultSet.Row> iter = resultSet.iterator();
+ for (int i = 0; i < rowCount; i++)
+ {
+ UntypedResultSet.Row row = iter.next();
+ assertEquals(i, row.getInt("k"));
+ }
+ }
+
+ @Test
+ public void testWriteWithSortedAndMaxSize() throws Exception {
+ String schema = "CREATE TABLE " + qualifiedTable + " ("
+ + " k int PRIMARY KEY,"
+ + " v blob )";
+ CQLSSTableWriter writer = CQLSSTableWriter.builder()
+ .inDirectory(dataDir)
Review Comment:
code format
##########
test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java:
##########
@@ -1116,6 +1117,78 @@ public void testFrozenSetTypeCustomOrdered() throws
Exception
assertEquals(0, filtered.size());
}
+ @Test
+ public void testWriteWithSorted() throws Exception
+ {
+ String schema = "CREATE TABLE " + qualifiedTable + " ("
+ + " k int PRIMARY KEY,"
+ + " v blob )";
+ CQLSSTableWriter writer = CQLSSTableWriter.builder()
+ .inDirectory(dataDir)
+ .forTable(schema)
+ .using("INSERT INTO " + qualifiedTable +
+ " (k, v) VALUES (?, textAsBlob(?))" )
+ .sorted()
+ .build();
+ int rowCount = 10_000;
+ for (int i = 0; i < rowCount; i++)
+ {
+ writer.addRow(i, UUID.randomUUID().toString());
+ }
+ writer.close();
+ loadSSTables(dataDir, keyspace);
+
+ UntypedResultSet resultSet = QueryProcessor.executeInternal("SELECT *
FROM " + qualifiedTable);
+ assertEquals(rowCount, resultSet.size());
+ Iterator<UntypedResultSet.Row> iter = resultSet.iterator();
+ for (int i = 0; i < rowCount; i++)
+ {
+ UntypedResultSet.Row row = iter.next();
+ assertEquals(i, row.getInt("k"));
+ }
+ }
+
+ @Test
+ public void testWriteWithSortedAndMaxSize() throws Exception {
+ String schema = "CREATE TABLE " + qualifiedTable + " ("
+ + " k int PRIMARY KEY,"
+ + " v blob )";
+ CQLSSTableWriter writer = CQLSSTableWriter.builder()
+ .inDirectory(dataDir)
+ .forTable(schema)
+ .using("INSERT INTO " + qualifiedTable +
+ " (k, v) VALUES (?, textAsBlob(?))")
+ .sorted()
+ .withMaxSSTableSizeInMiB(1)
+ .build();
+ int rowCount = 30_000;
+ // Max SSTable size is 1 MiB
+ // 30_000 rows should take 30_000 * (4 + 37) = 1.17 MiB > 1 MiB
+ for (int i = 0; i < rowCount; i++) {
+ writer.addRow(i, UUID.randomUUID().toString());
+ }
+ writer.close();
+
+ File[] dataFiles = dataDir.list(f ->
f.name().endsWith(Component.DATA.type.repr));
+ assertNotNull(dataFiles);
+ assertEquals("The sorted writer should produce 2 sstables when max
sstable size is configured",
+ 2, dataFiles.length);
Review Comment:
code format
##########
src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java:
##########
@@ -482,36 +486,56 @@ public Builder using(String modificationStatement)
return this;
}
+ /**
+ * Defines the maximum SSTable size in mebibytes when using the sorted
writer.
+ * By default, i.e. not specified, there is no maximum size limit for
the produced SSTable
+ *
+ * @param size the maximum sizein mebibytes of each individual SSTable
allowed
+ * @return this builder
+ */
+ public Builder withMaxSSTableSizeInMiB(int size)
+ {
+ if (size <= 0)
+ {
+ logger.warn("A non-positive value for maximum SSTable size is
specified, " +
+ "which disables the size limiting effectively. Please
supply a positive value in order " +
Review Comment:
code format
##########
test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java:
##########
@@ -1116,6 +1117,78 @@ public void testFrozenSetTypeCustomOrdered() throws
Exception
assertEquals(0, filtered.size());
}
+ @Test
+ public void testWriteWithSorted() throws Exception
+ {
+ String schema = "CREATE TABLE " + qualifiedTable + " ("
+ + " k int PRIMARY KEY,"
+ + " v blob )";
+ CQLSSTableWriter writer = CQLSSTableWriter.builder()
+ .inDirectory(dataDir)
+ .forTable(schema)
+ .using("INSERT INTO " + qualifiedTable +
+ " (k, v) VALUES (?, textAsBlob(?))" )
+ .sorted()
+ .build();
+ int rowCount = 10_000;
+ for (int i = 0; i < rowCount; i++)
+ {
+ writer.addRow(i, UUID.randomUUID().toString());
+ }
+ writer.close();
+ loadSSTables(dataDir, keyspace);
+
+ UntypedResultSet resultSet = QueryProcessor.executeInternal("SELECT *
FROM " + qualifiedTable);
+ assertEquals(rowCount, resultSet.size());
+ Iterator<UntypedResultSet.Row> iter = resultSet.iterator();
+ for (int i = 0; i < rowCount; i++)
+ {
+ UntypedResultSet.Row row = iter.next();
+ assertEquals(i, row.getInt("k"));
+ }
+ }
+
+ @Test
+ public void testWriteWithSortedAndMaxSize() throws Exception {
+ String schema = "CREATE TABLE " + qualifiedTable + " ("
+ + " k int PRIMARY KEY,"
+ + " v blob )";
+ CQLSSTableWriter writer = CQLSSTableWriter.builder()
+ .inDirectory(dataDir)
+ .forTable(schema)
+ .using("INSERT INTO " + qualifiedTable +
+ " (k, v) VALUES (?, textAsBlob(?))")
+ .sorted()
+ .withMaxSSTableSizeInMiB(1)
+ .build();
+ int rowCount = 30_000;
+ // Max SSTable size is 1 MiB
+ // 30_000 rows should take 30_000 * (4 + 37) = 1.17 MiB > 1 MiB
+ for (int i = 0; i < rowCount; i++) {
+ writer.addRow(i, UUID.randomUUID().toString());
+ }
+ writer.close();
+
+ File[] dataFiles = dataDir.list(f ->
f.name().endsWith(Component.DATA.type.repr));
+ assertNotNull(dataFiles);
+ assertEquals("The sorted writer should produce 2 sstables when max
sstable size is configured",
+ 2, dataFiles.length);
+ long closeTo1MiBFileSize = Math.max(dataFiles[0].length(),
dataFiles[1].length());
+ assertTrue("The file size should be close to 1MiB (with at most 50KiB
error rate for the test)",
+ Math.abs(1024 * 1024 - closeTo1MiBFileSize) < 50 * 1024);
Review Comment:
code format
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]