26
26
27
27
import org .apache .cassandra .db .compression .ICompressionDictionaryTrainer .TrainingStatus ;
28
28
import org .apache .cassandra .db .compression .ManualTrainingOptions ;
29
+ import org .apache .cassandra .io .util .FileUtils ;
29
30
import org .apache .cassandra .tools .NodeProbe ;
31
+ import org .apache .cassandra .tools .nodetool .formatter .TableBuilder ;
30
32
import org .apache .cassandra .utils .Clock ;
31
33
import picocli .CommandLine .Command ;
32
34
import picocli .CommandLine .Option ;
@@ -43,7 +45,7 @@ public class TrainCompressionDictionary extends AbstractCommand
43
45
private String table ;
44
46
45
47
@ Option (names = {"-d" , "--max-sampling-duration" },
46
- description = "Maximum time to collect samples before training dictionary (default: 600 seconds )" )
48
+ description = "Maximum time to collect samples before training dictionary, in seconds. (default: 600)" )
47
49
private int maxSamplingDurationSeconds = 600 ;
48
50
49
51
@ Option (names = {"-r" , "--sampling-rate" },
@@ -173,44 +175,46 @@ private void showTrainingStatus(NodeProbe probe)
173
175
}
174
176
175
177
TrainingStatus status = TrainingStatus .valueOf (statusStr );
178
+
176
179
switch (status )
177
180
{
178
181
case NOT_STARTED :
179
- out .printf ("Trainer is not running for %s.%s%n" , keyspace , table );
180
- break ;
181
182
case SAMPLING :
182
- out .printf ("Trainer is collecting sample data for %s.%s%n" , keyspace , table );
183
- showStatistics (probe , out );
184
- break ;
185
183
case TRAINING :
186
- out .printf ("Training is in progress for %s.%s%n" , keyspace , table );
187
- showStatistics (probe , out );
188
- break ;
189
184
case COMPLETED :
190
- out . printf ( "Training is completed for %s.%s%n" , keyspace , table );
185
+ showStatistics ( probe , out , status );
191
186
break ;
192
187
case FAILED :
193
- err . printf ( "Training failed for %s.%s%n" , keyspace , table );
188
+ showStatistics ( probe , err , status );
194
189
break ;
195
190
default :
196
191
err .printf ("Encountered unexpected training status for %s.%s: %s%n" , keyspace , table , status );
197
192
}
198
193
}
199
194
200
- private void showStatistics (NodeProbe probe , PrintStream out )
195
+ private void showStatistics (NodeProbe probe , PrintStream out , TrainingStatus status )
201
196
{
202
197
try
203
198
{
204
- long sampleCount = probe .getCompressionDictionaryTrainingSampleCount (keyspace , table );
205
- long totalSampleSize = probe .getCompressionDictionaryTrainingTotalSampleSize (keyspace , table );
206
- double sampleSizeMB = totalSampleSize / (1024.0 * 1024.0 );
199
+ TableBuilder tableBuilder = new TableBuilder ();
200
+ tableBuilder .add ("keyspace" , keyspace );
201
+ tableBuilder .add ("table" , table );
202
+ tableBuilder .add ("status" , status .name ());
203
+
204
+ if (status == TrainingStatus .SAMPLING || status == TrainingStatus .TRAINING )
205
+ {
206
+ long sampleCount = probe .getCompressionDictionaryTrainingSampleCount (keyspace , table );
207
+ long totalSampleSize = probe .getCompressionDictionaryTrainingTotalSampleSize (keyspace , table );
208
+
209
+ tableBuilder .add ("samples collected" , String .format ("%d" , sampleCount ));
210
+ tableBuilder .add ("total sample size" , FileUtils .stringifyFileSize (totalSampleSize ));
211
+ }
207
212
208
- out .printf (" Samples collected: %d%n" , sampleCount );
209
- out .printf (" Total sample size: %.2f MiB%n" , sampleSizeMB );
213
+ tableBuilder .printTo (out );
210
214
}
211
215
catch (Exception e )
212
216
{
213
- out .printf (" Unable to retrieve training statistics: %s%n" , e .getMessage ());
217
+ out .printf ("Unable to retrieve training statistics: %s%n" , e .getMessage ());
214
218
}
215
219
}
216
220
}
0 commit comments