@@ -142,26 +142,19 @@ public int bufferSizeInBytes() {
142
142
}
143
143
144
144
@ Override public void delete (BlobPath path ) {
145
- logger .debug ("TODO delete {}" , path );
146
- /* XXX TODO
147
- ObjectListing prevListing = null;
148
- while (true) {
149
- ObjectListing list;
150
- if (prevListing != null) {
151
- list = client.listNextBatchOfObjects(prevListing);
152
- } else {
153
- list = client.listObjects(bucket, path.buildAsString("/"));
154
- }
155
- for (S3ObjectSummary summary : list.getObjectSummaries()) {
156
- client.deleteObject(summary.getBucketName(), summary.getKey());
157
- }
158
- if (list.isTruncated()) {
159
- prevListing = list;
160
- } else {
161
- break;
162
- }
145
+ String blobPath = path .buildAsString ("/" );
146
+ logger .debug ("TODO delete {}" , blobPath );
147
+ try {
148
+ ImmutableMap <String , BlobMetaData > blobs =
149
+ listBlobsByPrefix (blobPath , null );
150
+ String [] blobNames =
151
+ blobs .keySet ().toArray (new String [blobs .size ()]);
152
+ deleteBlobs (blobPath , blobNames );
153
+ }
154
+ catch (IOException ex ) {
155
+ // Oh well, nothing we can do but log.
156
+ logger .warn ("delete {} failed" , ex , blobPath );
163
157
}
164
- */
165
158
}
166
159
167
160
@ Override public void close () {
@@ -189,19 +182,26 @@ boolean blobExists(String blobPath, String blobName) {
189
182
}
190
183
191
184
boolean deleteBlob (String blobPath , String blobName ) throws IOException {
192
- String blobKey = blobKey (blobPath , blobName );
193
- logger .debug ("deleteBlob {}" , blobKey );
194
- Cassandra .Client client =
195
- CassandraClientFactory .getCassandraClient ();
196
- try {
197
- long timestamp = System .currentTimeMillis ();
185
+ logger .debug ("deleteBlob {}" , blobKey (blobPath , blobName ));
186
+ return deleteBlobs (blobPath , blobName );
187
+ }
198
188
199
- Map <String , Map <String , List <Mutation >>> mutationMap =
200
- new HashMap <String , Map <String , List <Mutation >>>();
189
+ private boolean deleteBlobs (String blobPath , String ... blobNames )
190
+ throws IOException
191
+ {
192
+ long timestamp = System .currentTimeMillis ();
201
193
202
- // Delete the blob data from Blobs.
194
+ Map <String , Map <String , List <Mutation >>> mutationMap =
195
+ new HashMap <String , Map <String , List <Mutation >>>();
196
+
197
+ List <Mutation > blobNamesMutations = new ArrayList <Mutation >();
203
198
204
- List <Mutation > blobsMutations = new ArrayList <Mutation >();
199
+ for (String blobName : blobNames ) {
200
+ String blobKey = blobKey (blobPath , blobName );
201
+
202
+ // Delete the blob data from Blobs.
203
+
204
+ List <Mutation > blobsMutations = new ArrayList <Mutation >(1 );
205
205
blobsMutations .add (createDelete (null , timestamp ));
206
206
207
207
Map <String , List <Mutation >> blobsMutationMap =
@@ -212,18 +212,20 @@ boolean deleteBlob(String blobPath, String blobName) throws IOException {
212
212
213
213
// Delete the blobName from BlobNames.
214
214
215
- List <Mutation > blobNamesMutations = new ArrayList <Mutation >();
216
215
blobNamesMutations .add (createDelete (blobName , timestamp ));
216
+ }
217
217
218
- Map <String , List <Mutation >> blobNamesMutationMap =
219
- new HashMap <String , List <Mutation >>();
220
- blobNamesMutationMap .put ("BlobNames" , blobNamesMutations );
218
+ Map <String , List <Mutation >> blobNamesMutationMap =
219
+ new HashMap <String , List <Mutation >>();
220
+ blobNamesMutationMap .put ("BlobNames" , blobNamesMutations );
221
221
222
- mutationMap .put (blobPath , blobNamesMutationMap );
222
+ mutationMap .put (blobPath , blobNamesMutationMap );
223
223
224
+ Cassandra .Client client = null ;
225
+ try {
226
+ client = CassandraClientFactory .getCassandraClient ();
224
227
client .batch_mutate (
225
228
keySpace , mutationMap , ConsistencyLevel .QUORUM );
226
-
227
229
return true ;
228
230
}
229
231
catch (Exception e ) {
@@ -232,7 +234,9 @@ boolean deleteBlob(String blobPath, String blobName) throws IOException {
232
234
return false ;
233
235
}
234
236
finally {
235
- CassandraClientFactory .closeCassandraClient (client );
237
+ if (client != null ) {
238
+ CassandraClientFactory .closeCassandraClient (client );
239
+ }
236
240
}
237
241
}
238
242
0 commit comments