Skip to content

Commit

Permalink
LDEV-4754 - add additional log when threshold reached
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Nov 16, 2023
1 parent efb9bbd commit f290b23
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build.number
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Wed Nov 15 10:40:45 CET 2023
build.number=10
#Thu Nov 16 14:21:37 CET 2023
build.number=12
38 changes: 38 additions & 0 deletions source/java/src/org/lucee/extension/resource/s3/S3.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public class S3 {
public static final String[] PROVIDERS = new String[] { AWS, WASABI, BACKBLAZE, ".digitaloceanspaces.com", DREAM_IO, GOOGLE };

private static final ConcurrentHashMap<String, Object> tokens = new ConcurrentHashMap<String, Object>();
private static int errorThreshold = 0;
private static int warnThreshold = 0;

private static Map<String, S3> instances = new ConcurrentHashMap<String, S3>();
private static Map<String, S3Cache> caches = new ConcurrentHashMap<String, S3Cache>();
Expand Down Expand Up @@ -130,6 +132,22 @@ public static S3 getInstance(S3Properties props, long cache, Config config) {
s3 = instances.get(keyS3);
if (s3 == null) {

if (errorThreshold == 0) {
synchronized (AWS) {
if (errorThreshold == 0) {
errorThreshold = CFMLEngineFactory.getInstance().getCastUtil().toIntValue(S3Util.getSystemPropOrEnvVar("lucee.s3.listErrorThreshold", null),
100000);
}
}
}
if (warnThreshold == 0) {
synchronized (AWS) {
if (warnThreshold == 0) {
warnThreshold = CFMLEngineFactory.getInstance().getCastUtil().toIntValue(S3Util.getSystemPropOrEnvVar("lucee.s3.listWarnThreshold", null), 10000);
}
}
}

String keyCache = props.getAccessKeyId() + ":" + props.getSecretAccessKey() + ":" + props.getHostWithoutRegion() + ":" + cache;
S3Cache c = caches.get(keyCache);
if (c == null) {
Expand Down Expand Up @@ -751,6 +769,8 @@ public List<S3Object> listObjects(String bucketName) throws S3Exception {
List<S3ObjectSummary> summeries = objects.getObjectSummaries();
if (summeries != null) {
sum += summeries.size();
// we do it already here to avoid a OOME later on
if (sum >= warnThreshold) logThreshold(sum, bucketName);
while (true) {
for (S3ObjectSummary summary: summeries) {
fixBackBlazeBug(summary, bucketName);
Expand All @@ -777,6 +797,20 @@ public List<S3Object> listObjects(String bucketName) throws S3Exception {
}
}

private void logThreshold(int sum, String endpoint) {
String msg = "High volume of records (" + sum + ") encountered while listing objects in S3 bucket [" + endpoint + "].";
if (log == null) {
System.err.println(msg);
}
else {
log.log(sum >= errorThreshold ? Log.LEVEL_ERROR : Log.LEVEL_WARN, "S3", msg, createThrow(msg));
}
}

private Throwable createThrow(String message) {
return new Exception(message);
}

public Query listBucketsAsQuery() throws S3Exception, PageException {
AmazonS3Client client = getAmazonS3(null, null);
try {
Expand Down Expand Up @@ -835,6 +869,7 @@ public Query listObjectsAsQuery(String bucketName) throws S3Exception, PageExcep
while (true) {
summeries = objects.getObjectSummaries();
sum += summeries.size();
if (sum >= warnThreshold) logThreshold(sum, bucketName);
for (S3ObjectSummary summary: summeries) {
fixBackBlazeBug(summary, bucketName);
row = qry.addRow();
Expand Down Expand Up @@ -957,6 +992,7 @@ private ValidUntilMap<S3Info> _list(String bucketName, String objectName, boolea
while (true) {
List<S3ObjectSummary> kids = list.getObjectSummaries();
sum += kids.size();
if (sum >= warnThreshold) logThreshold(sum, bucketName + "/" + nameFile);
StorageObjectWrapper tmp;
String name;
for (S3ObjectSummary kid: kids) {
Expand Down Expand Up @@ -1291,6 +1327,7 @@ public void delete(String bucketName, String objectName, boolean force) throws S
while (true) {
summeries = objects.getObjectSummaries();
sum += summeries.size();
if (sum >= warnThreshold) logThreshold(sum, bucketName + "/" + nameFile);
for (S3ObjectSummary summary: summeries) {
fixBackBlazeBug(summary, bucketName);
if (summary.getKey().equals(nameFile)) {
Expand Down Expand Up @@ -1364,6 +1401,7 @@ public void clear(String bucketName, long maxAge) throws S3Exception {
while (true) {
List<S3ObjectSummary> summeries = objects.getObjectSummaries();
sum += summeries.size();
if (sum >= warnThreshold) logThreshold(sum, bucketName);
List<KeyVersion> filtered = toObjectKeyAndVersions(summeries, maxAge);
if (filtered != null && filtered.size() > 0) {
DeleteObjectsRequest dor = new DeleteObjectsRequest(bucketName).withKeys(filtered).withQuiet(false);
Expand Down

0 comments on commit f290b23

Please sign in to comment.