
com.couchbase.transactions.log.TransactionCleanupStartRunEvent Maven / Gradle / Ivy
Show all versions of couchbase-transactions Show documentation
/*
* Copyright 2021 Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.couchbase.transactions.log;
import com.couchbase.client.core.annotation.Stability;
import com.couchbase.transactions.cleanup.ClientRecordDetails;
import com.couchbase.transactions.cleanup.TransactionsCleanup;
import java.time.Duration;
/**
* Emitted periodically with a summary of what will be done soon for cleanup.
*
* As this exposes implementation details of transactions, all methods are subject to change and marked
* with @Stability.Volatile.
*/
@Stability.Volatile
public class TransactionCleanupStartRunEvent extends TransactionEvent {
private final String bucketName;
private final String scopeName;
private final String collectionName;
private final String clientId;
private final ClientRecordDetails clientDetails;
private final Duration cleanupWindow;
private final int atrsToCheckInNextWindow;
private final int totalAtrs;
private final Duration checkAtrEvery;
@Stability.Volatile
public TransactionCleanupStartRunEvent(String bucketName,
String scopeName,
String collectionName,
String clientUuid,
ClientRecordDetails clientDetails,
Duration cleanupWindow,
int atrsToCheckInNextWindow,
int totalAtrs,
Duration checkAtrEvery) {
// All this info is included in TransactionCleanupEndRunEvent too (published at INFO), so publish this at DEBUG
super(Severity.DEBUG, TransactionsCleanup.CATEGORY_STATS);
this.bucketName = bucketName;
this.scopeName = scopeName;
this.collectionName = collectionName;
this.clientId = clientUuid;
this.clientDetails = clientDetails;
this.cleanupWindow = cleanupWindow;
this.atrsToCheckInNextWindow = atrsToCheckInNextWindow;
this.totalAtrs = totalAtrs;
this.checkAtrEvery = checkAtrEvery;
}
/**
* The numeric index of the client in a sorted list of active clients.
*/
@Stability.Volatile
public int clientIndex() {
return clientDetails.indexOfThisClient();
}
/**
* The total active, alive clients taking part in cleanup, including this one.
*/
@Stability.Volatile
public int totalActiveClients() {
return clientDetails.numActiveClients();
}
/**
* All ATRs are checked once every cleanupWindow.
*/
@Stability.Volatile
public Duration cleanupWindow() {
return cleanupWindow;
}
/**
* How many ATRs this client will check over the next cleanupWindow.
*/
@Stability.Volatile
public int atrsToCheckInNextWindow() {
return atrsToCheckInNextWindow;
}
/**
* The total number of ATRs being checked by all clients.
*/
@Stability.Volatile
public int totalAtrs() {
return totalAtrs;
}
/**
* How regular an ATR should be checked by this client over the next cleanupWindow.
*/
@Stability.Volatile
public Duration checkAtrEvery() {
return checkAtrEvery;
}
/**
* The bucket containing the ATRs being checked by this cleanup.
*/
@Stability.Volatile
public String bucketName() {
return bucketName;
}
/**
* The collection containing the ATRs being checked by this cleanup.
*/
@Stability.Volatile
public String collectionName() {
return collectionName;
}
/**
* The unique ID of the this client (application).
*/
@Stability.Volatile
public String clientUuid() {
return clientId;
}
@Override
public String description() {
StringBuilder sb = new StringBuilder(200);
sb.append(bucketName);
sb.append('.');
sb.append(scopeName);
sb.append('.');
sb.append(collectionName);
sb.append("/clientId=");
sb.append(clientId.substring(0, LogDefer.CHARS_TO_LOG));
sb.append(",index=");
sb.append(clientDetails.indexOfThisClient());
sb.append(",numClients=");
sb.append(clientDetails.numActiveClients());
sb.append(",ATRs={checking=");
sb.append(atrsToCheckInNextWindow);
// Note this is expected total, not how many actually exist
sb.append(",total=");
sb.append(totalAtrs);
sb.append("},runLength=");
sb.append(cleanupWindow.toMillis());
sb.append("millis");
return sb.toString();
}
@Override
public boolean success() {
return true;
}
}