Skip to content

Commit 44363eb

Browse files
committed
Improve Ample logging for rejected conditional mutations
1 parent 9f3ad6e commit 44363eb

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

core/src/main/java/org/apache/accumulo/core/metadata/schema/Ample.java

+11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Set;
2525
import java.util.function.Consumer;
2626
import java.util.function.Predicate;
27+
import java.util.function.Supplier;
2728

2829
import org.apache.accumulo.core.client.ConditionalWriter;
2930
import org.apache.accumulo.core.client.admin.TabletAvailability;
@@ -623,6 +624,16 @@ ConditionalTabletMutator requireSame(TabletMetadata tabletMetadata, ColumnType t
623624
* let the rejected status carry forward in this case.
624625
*/
625626
void submit(RejectionHandler rejectionHandler);
627+
628+
/**
629+
* Overloaded version of {@link #submit(RejectionHandler)} that takes a short description of the
630+
* operation to assist with debugging.
631+
*
632+
* @param rejectionHandler The rejection handler
633+
* @param description A short description of the operation (e.g., "bulk import", "compaction")
634+
*/
635+
void submit(RejectionHandler rejectionHandler, Supplier<String> description);
636+
626637
}
627638

628639
/**

server/base/src/main/java/org/apache/accumulo/server/metadata/ConditionalTabletMutatorImpl.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.function.BiConsumer;
3737
import java.util.function.Consumer;
3838
import java.util.function.Function;
39+
import java.util.function.Supplier;
3940

4041
import org.apache.accumulo.core.client.IteratorSetting;
4142
import org.apache.accumulo.core.client.admin.TabletAvailability;
@@ -86,17 +87,20 @@ public class ConditionalTabletMutatorImpl extends TabletMutatorBase<Ample.Condit
8687
private final ServerContext context;
8788
private final ServiceLock lock;
8889
private final KeyExtent extent;
90+
private final BiConsumer<KeyExtent,Supplier<String>> descriptionConsumer;
8991

9092
private boolean sawOperationRequirement = false;
9193
private boolean checkPrevEndRow = true;
9294

9395
protected ConditionalTabletMutatorImpl(ServerContext context, KeyExtent extent,
9496
Consumer<ConditionalMutation> mutationConsumer,
95-
BiConsumer<KeyExtent,Ample.RejectionHandler> rejectionHandlerConsumer) {
97+
BiConsumer<KeyExtent,Ample.RejectionHandler> rejectionHandlerConsumer,
98+
BiConsumer<KeyExtent,Supplier<String>> descriptionConsumer) {
9699
super(new ConditionalMutation(extent.toMetaRow()));
97100
this.mutation = (ConditionalMutation) super.mutation;
98101
this.mutationConsumer = mutationConsumer;
99102
this.rejectionHandlerConsumer = rejectionHandlerConsumer;
103+
this.descriptionConsumer = descriptionConsumer;
100104
this.extent = extent;
101105
this.context = context;
102106
this.lock = this.context.getServiceLock();
@@ -390,4 +394,10 @@ public void submit(Ample.RejectionHandler rejectionCheck) {
390394
mutationConsumer.accept(mutation);
391395
rejectionHandlerConsumer.accept(extent, rejectionCheck);
392396
}
397+
398+
@Override
399+
public void submit(Ample.RejectionHandler rejectionHandler, Supplier<String> description) {
400+
descriptionConsumer.accept(extent, description);
401+
this.submit(rejectionHandler);
402+
}
393403
}

server/base/src/main/java/org/apache/accumulo/server/metadata/ConditionalTabletsMutatorImpl.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Optional;
3131
import java.util.Set;
3232
import java.util.function.Function;
33+
import java.util.function.Supplier;
3334
import java.util.stream.Collectors;
3435

3536
import org.apache.accumulo.core.client.AccumuloException;
@@ -66,6 +67,7 @@ public class ConditionalTabletsMutatorImpl implements Ample.ConditionalTabletsMu
6667
private boolean active = true;
6768

6869
final Map<KeyExtent,Ample.RejectionHandler> rejectedHandlers = new HashMap<>();
70+
private final Map<KeyExtent,Supplier<String>> operationDescriptions = new HashMap<>();
6971
private final Function<DataLevel,String> tableMapper;
7072

7173
public ConditionalTabletsMutatorImpl(ServerContext context) {
@@ -93,7 +95,8 @@ public Ample.OperationRequirements mutateTablet(KeyExtent extent) {
9395

9496
Preconditions.checkState(extents.putIfAbsent(extent.toMetaRow(), extent) == null,
9597
"Duplicate extents not handled %s", extent);
96-
return new ConditionalTabletMutatorImpl(context, extent, mutations::add, rejectedHandlers::put);
98+
return new ConditionalTabletMutatorImpl(context, extent, mutations::add, rejectedHandlers::put,
99+
operationDescriptions::put);
97100
}
98101

99102
protected ConditionalWriter createConditionalWriter(Ample.DataLevel dataLevel)
@@ -262,16 +265,20 @@ public Status getStatus() {
262265
status = Status.ACCEPTED;
263266
}
264267

268+
Supplier<String> descSupplier = operationDescriptions.get(extent);
269+
String desc = (descSupplier == null) ? null : descSupplier.get();
270+
265271
if (log.isTraceEnabled()) {
266272
// log detailed info about tablet metadata and mutation
267-
log.trace("Mutation was rejected, status:{} {} {}", status, tabletMetadata,
268-
result.getMutation().prettyPrint());
273+
log.trace("Mutation was rejected, status:{}. Operation description: {} {} {}",
274+
status, desc, tabletMetadata, result.getMutation().prettyPrint());
269275
} else if (log.isDebugEnabled()) {
270276
// log a single line of info that makes it apparent this happened and gives enough
271277
// information to investigate
272-
log.debug("Mutation was rejected, status:{} extent:{} row:{}", status,
273-
tabletMetadata == null ? null : tabletMetadata.getExtent(),
274-
new String(result.getMutation().getRow(), UTF_8));
278+
log.debug(
279+
"Mutation was rejected, status:{} extent:{} row:{} operation description: {}",
280+
status, tabletMetadata == null ? null : tabletMetadata.getExtent(),
281+
new String(result.getMutation().getRow(), UTF_8), desc);
275282
}
276283
}
277284

test/src/main/java/org/apache/accumulo/test/functional/AmpleConditionalWriterIT.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ public void testLocations() throws Exception {
173173
// test require absent with a future location set
174174
try (var ctmi = new ConditionalTabletsMutatorImpl(context)) {
175175
ctmi.mutateTablet(e1).requireAbsentOperation().requireAbsentLocation()
176-
.putLocation(Location.future(ts2)).submit(tm -> false);
176+
.putLocation(Location.future(ts2)).submit(tm -> false,
177+
() -> "Testing that requireAbsentLocation() fails when a future location is set");
177178
assertEquals(Status.REJECTED, ctmi.process().get(e1).getStatus());
178179
}
179180
assertEquals(Location.future(ts1), context.getAmple().readTablet(e1).getLocation());
@@ -196,7 +197,8 @@ public void testLocations() throws Exception {
196197
try (var ctmi = new ConditionalTabletsMutatorImpl(context)) {
197198
ctmi.mutateTablet(e1).requireAbsentOperation().requireAbsentLocation()
198199
.putLocation(Location.future(ts2)).submit(tm -> false);
199-
assertEquals(Status.REJECTED, ctmi.process().get(e1).getStatus());
200+
assertEquals(Status.REJECTED, ctmi.process().get(e1).getStatus(),
201+
() -> "Testing that requireAbsentLocation() fails when a current location is set");
200202
}
201203
assertEquals(Location.current(ts1), context.getAmple().readTablet(e1).getLocation());
202204

0 commit comments

Comments
 (0)