use of co.cask.cdap.logging.clean.FileMetadataCleaner in project cdap by caskdata.
the class CDAPLogAppender method start.
@Override
public void start() {
// These should all passed. The settings are from the cdap-log-pipeline.xml and the context must be AppenderContext
Preconditions.checkState(dirPermissions != null, "Property dirPermissions cannot be null");
Preconditions.checkState(filePermissions != null, "Property filePermissions cannot be null");
Preconditions.checkState(syncIntervalBytes > 0, "Property syncIntervalBytes must be > 0.");
Preconditions.checkState(maxFileLifetimeMs > 0, "Property maxFileLifetimeMs must be > 0");
Preconditions.checkState(maxFileSizeInBytes > 0, "Property maxFileSizeInBytes must be > 0");
Preconditions.checkState(fileRetentionDurationDays > 0, "Property fileRetentionDurationDays must be > 0");
Preconditions.checkState(logCleanupIntervalMins > 0, "Property logCleanupIntervalMins must be > 0");
Preconditions.checkState(fileCleanupTransactionTimeout > Constants.Logging.TX_TIMEOUT_DISCOUNT_SECS, String.format("Property fileCleanupTransactionTimeout must be greater than %s seconds", Constants.Logging.TX_TIMEOUT_DISCOUNT_SECS));
if (context instanceof AppenderContext) {
AppenderContext context = (AppenderContext) this.context;
logFileManager = new LogFileManager(dirPermissions, filePermissions, maxFileLifetimeMs, maxFileSizeInBytes, syncIntervalBytes, new FileMetaDataWriter(context.getDatasetManager(), context), context.getLocationFactory());
if (context.getInstanceId() == 0) {
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(Threads.createDaemonThreadFactory("log-clean-up"));
FileMetadataCleaner fileMetadataCleaner = new FileMetadataCleaner(context.getDatasetManager(), context);
LogCleaner logCleaner = new LogCleaner(fileMetadataCleaner, context.getLocationFactory(), TimeUnit.DAYS.toMillis(fileRetentionDurationDays), fileCleanupTransactionTimeout);
scheduledExecutorService.scheduleAtFixedRate(logCleaner, 10, logCleanupIntervalMins, TimeUnit.MINUTES);
}
} else if (!Boolean.TRUE.equals(context.getObject(Constants.Logging.PIPELINE_VALIDATION))) {
throw new IllegalStateException("Expected logger context instance of " + AppenderContext.class.getName() + " but get " + context.getClass().getName());
}
super.start();
}
Aggregations