-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid infinite number of calls to listBlobs when doing prefix removals (e..g, gridset or layer removals) #1232
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
import static org.geowebcache.azure.AzureBlobStore.log; | ||
import static org.springframework.http.HttpStatus.NOT_FOUND; | ||
|
||
import com.google.common.base.Strings; | ||
import com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
import com.microsoft.azure.storage.blob.ContainerURL; | ||
import com.microsoft.azure.storage.blob.ListBlobsOptions; | ||
|
@@ -26,9 +27,11 @@ | |
import com.microsoft.rest.v2.RestException; | ||
import java.io.Closeable; | ||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import java.util.Set; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ExecutionException; | ||
|
@@ -169,14 +172,21 @@ public void issuePendingBulkDeletes() throws StorageException { | |
|
||
try { | ||
Properties deletes = client.getProperties(pendingDeletesKey); | ||
Set<String> deletesToClear = new HashSet<>(); | ||
for (Map.Entry<Object, Object> e : deletes.entrySet()) { | ||
final String prefix = e.getKey().toString(); | ||
final long timestamp = Long.parseLong(e.getValue().toString()); | ||
log.info( | ||
String.format( | ||
"Restarting pending bulk delete on '%s/%s':%d", | ||
client.getContainerName(), prefix, timestamp)); | ||
asyncDelete(prefix, timestamp); | ||
if (!asyncDelete(prefix, timestamp)) { | ||
deletesToClear.add(prefix); | ||
} | ||
} | ||
if (!deletesToClear.isEmpty()) { | ||
deletes.keySet().removeAll(deletesToClear); | ||
client.putProperties(pendingDeletesKey, deletes); | ||
} | ||
} finally { | ||
try { | ||
|
@@ -281,12 +291,10 @@ public Long call() throws Exception { | |
checkInterrupted(); | ||
deleteItems(container, response.body().segment(), filter); | ||
String marker = response.body().nextMarker(); | ||
if (marker != null) { | ||
response = | ||
container.listBlobsFlatSegment(marker, options, null).blockingGet(); | ||
} else { | ||
break; | ||
} | ||
// marker will be empty if there is no next page | ||
if (Strings.isNullOrEmpty(marker)) break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the actual fix for the high number of listBlob. It would just not get out of this loop. |
||
// fetch next page | ||
response = container.listBlobsFlatSegment(marker, options, null).blockingGet(); | ||
} | ||
} catch (InterruptedException | IllegalStateException e) { | ||
log.info( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,12 @@ | |
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.AdditionalMatchers.or; | ||
import static org.mockito.ArgumentMatchers.anyInt; | ||
import static org.mockito.ArgumentMatchers.anyLong; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.ArgumentMatchers.isNull; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
@@ -36,6 +38,7 @@ | |
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.logging.Logger; | ||
import org.geotools.util.logging.Logging; | ||
|
@@ -154,7 +157,7 @@ public void testPutWithListener() throws MimeException, StorageException { | |
eq(tile.getLayerName()), | ||
eq(tile.getGridSetId()), | ||
eq(tile.getBlobFormat()), | ||
anyString(), | ||
anyStringOrNull(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are changes in Mockito behavior, previous version was matching null too, the current one does not. |
||
eq(20L), | ||
eq(30L), | ||
eq(12), | ||
|
@@ -171,7 +174,7 @@ public void testPutWithListener() throws MimeException, StorageException { | |
eq(tile.getLayerName()), | ||
eq(tile.getGridSetId()), | ||
eq(tile.getBlobFormat()), | ||
anyString(), | ||
anyStringOrNull(), | ||
eq(20L), | ||
eq(30L), | ||
eq(12), | ||
|
@@ -212,7 +215,7 @@ public void testDelete() throws MimeException, StorageException { | |
eq(tile.getLayerName()), | ||
eq(tile.getGridSetId()), | ||
eq(tile.getBlobFormat()), | ||
anyString(), | ||
anyStringOrNull(), | ||
eq(22L), | ||
eq(30L), | ||
eq(12), | ||
|
@@ -397,7 +400,7 @@ public void testTruncateShortCutsIfNoTilesInParametersPrefix() | |
anyString(), | ||
anyString(), | ||
anyString(), | ||
anyString(), | ||
anyStringOrNull(), | ||
anyLong(), | ||
anyLong(), | ||
anyInt(), | ||
|
@@ -493,21 +496,26 @@ public void testTruncateRespectsLevels() throws StorageException, MimeException | |
|
||
verify(listener, times(expectedCount)) | ||
.tileDeleted( | ||
anyString(), | ||
anyString(), | ||
anyString(), | ||
anyString(), | ||
anyStringOrNull(), | ||
anyStringOrNull(), | ||
anyStringOrNull(), | ||
anyStringOrNull(), | ||
anyLong(), | ||
anyLong(), | ||
anyInt(), | ||
anyLong()); | ||
} | ||
|
||
private static String anyStringOrNull() { | ||
return or(isNull(), anyString()); | ||
} | ||
|
||
/** | ||
* If there are not {@link BlobStoreListener}s, use an optimized code path (not calling delete() | ||
* for each tile) | ||
*/ | ||
@Test | ||
@SuppressWarnings("unchecked") | ||
public void testTruncateOptimizationIfNoListeners() throws StorageException, MimeException { | ||
|
||
final int zoomStart = 0; | ||
|
@@ -537,10 +545,12 @@ public void testTruncateOptimizationIfNoListeners() throws StorageException, Mim | |
mimeType, | ||
parameters); | ||
|
||
blobStore = Mockito.spy(blobStore); | ||
@SuppressWarnings("PMD.CloseResource") // closed by the store | ||
DeleteManager deleteManager = Mockito.spy(blobStore.deleteManager); | ||
assertTrue(blobStore.delete(tileRange)); | ||
|
||
verify(blobStore, times(0)).delete(Mockito.any(TileObject.class)); | ||
verify(deleteManager, times(0)).executeParallel(Mockito.any(List.class)); | ||
|
||
assertFalse(blobStore.get(queryTile(0, 0, 0))); | ||
assertFalse(blobStore.get(queryTile(0, 0, 1))); | ||
assertFalse(blobStore.get(queryTile(0, 1, 1))); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scheduled deletes stored in property files would not get removed if the folder was empty.