Trying to speed up table truncate

This commit is contained in:
Martin Stockhammer 2021-08-29 13:57:22 +02:00
parent 20918cb383
commit d0aa5dd637
2 changed files with 20 additions and 12 deletions

View File

@ -396,7 +396,7 @@
<addTestClasspath>false</addTestClasspath> <addTestClasspath>false</addTestClasspath>
<startWaitSeconds>500</startWaitSeconds> <startWaitSeconds>500</startWaitSeconds>
<startNativeTransport>true</startNativeTransport> <startNativeTransport>true</startNativeTransport>
<logLevel>DEBUG</logLevel> <logLevel>INFO</logLevel>
<loadAfterFirstStart>false</loadAfterFirstStart> <loadAfterFirstStart>false</loadAfterFirstStart>
<yaml> <yaml>
broadcast_rpc_address: 127.0.0.1 broadcast_rpc_address: 127.0.0.1
@ -404,6 +404,7 @@
<systemPropertyVariables> <systemPropertyVariables>
<java.net.preferIPv4Stack>true</java.net.preferIPv4Stack> <java.net.preferIPv4Stack>true</java.net.preferIPv4Stack>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</execution> </execution>
<execution> <execution>

View File

@ -44,7 +44,10 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.truncate; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.truncate;
import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.dropTable; import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.dropTable;
@ -72,7 +75,7 @@ public class CassandraMetadataRepositoryTest
long cTime; long cTime;
int testNum = 0; int testNum = 0;
AtomicBoolean clearedTables = new AtomicBoolean( false ); final AtomicBoolean clearedTables = new AtomicBoolean( false );
@Override @Override
@ -121,8 +124,7 @@ public class CassandraMetadataRepositoryTest
if (!clearedTables.get()) if (!clearedTables.get())
{ {
clearReposAndNamespace( cassandraArchivaManager ); clearReposAndNamespace( cassandraArchivaManager, clearedTables );
clearedTables.set( true );
} }
System.err.println( "Finished setting up - "+testInfo.getDisplayName() + " - " + (System.currentTimeMillis( ) - cTime) +"ms"); System.err.println( "Finished setting up - "+testInfo.getDisplayName() + " - " + (System.currentTimeMillis( ) - cTime) +"ms");
} }
@ -164,13 +166,12 @@ public class CassandraMetadataRepositoryTest
throws Exception throws Exception
{ {
System.err.println( "Shutting down - " + (testNum-1) + " - " + testInfo.getDisplayName( ) + " - " + ( System.currentTimeMillis( ) - cTime ) +"ms"); System.err.println( "Shutting down - " + (testNum-1) + " - " + testInfo.getDisplayName( ) + " - " + ( System.currentTimeMillis( ) - cTime ) +"ms");
clearReposAndNamespace( cassandraArchivaManager ); clearReposAndNamespace( cassandraArchivaManager, clearedTables );
clearedTables.set( true );
super.tearDown(); super.tearDown();
System.err.println( "Shutting down finished - " + testInfo.getDisplayName( ) + " - " + ( System.currentTimeMillis( ) - cTime ) +"ms"); System.err.println( "Shutting down finished - " + testInfo.getDisplayName( ) + " - " + ( System.currentTimeMillis( ) - cTime ) +"ms");
} }
static void clearReposAndNamespace( CassandraArchivaManager cassandraArchivaManager ) static void clearReposAndNamespace( final CassandraArchivaManager cassandraArchivaManager, final AtomicBoolean clearedFlag )
throws Exception throws Exception
{ {
if (cassandraArchivaManager!=null) if (cassandraArchivaManager!=null)
@ -188,15 +189,21 @@ public class CassandraMetadataRepositoryTest
cassandraArchivaManager.getLicenseFamilyName( ), cassandraArchivaManager.getLicenseFamilyName( ),
cassandraArchivaManager.getDependencyFamilyName( ) cassandraArchivaManager.getDependencyFamilyName( )
); );
for ( String table : tables ) CompletableFuture.allOf( tables.stream( ).map( table -> session.executeAsync( truncate( table ).build( ) ) )
{ .map( CompletionStage::toCompletableFuture ).collect( Collectors.toList( ) ).toArray( new CompletableFuture[0] ) )
session.execute( truncate( table ).build( ) ); .thenAccept( ( c ) -> {
} if ( clearedFlag != null ) clearedFlag.set( true );
} ).get( )
;
} }
} else { } else {
System.err.println( "cassandraArchivaManager is null" ); System.err.println( "cassandraArchivaManager is null" );
} }
} }
static void clearReposAndNamespace( final CassandraArchivaManager cassandraArchivaManager)
throws Exception {
clearReposAndNamespace( cassandraArchivaManager, null );
}
} }