|
21 | 21 | import java.io.Serializable;
|
22 | 22 | import java.util.EnumSet;
|
23 | 23 | import java.util.Map;
|
| 24 | +import java.util.Objects; |
24 | 25 | import java.util.Optional;
|
| 26 | +import java.util.concurrent.CompletableFuture; |
25 | 27 | import java.util.concurrent.atomic.AtomicBoolean;
|
26 | 28 | import java.util.function.Consumer;
|
27 | 29 | import java.util.function.Function;
|
28 | 30 | import java.util.stream.Stream;
|
29 | 31 |
|
30 | 32 | import org.apache.accumulo.core.fate.Fate;
|
| 33 | +import org.apache.accumulo.core.fate.Fate.FateOperation; |
31 | 34 | import org.apache.accumulo.core.fate.FateId;
|
32 | 35 | import org.apache.accumulo.core.fate.FateInstanceType;
|
33 | 36 | import org.apache.accumulo.core.fate.FateKey;
|
34 | 37 | import org.apache.accumulo.core.fate.FateStore;
|
35 | 38 | import org.apache.accumulo.core.fate.FateStore.FateTxStore;
|
| 39 | +import org.apache.accumulo.core.fate.FateStore.Seeder; |
36 | 40 | import org.apache.accumulo.core.fate.ReadOnlyFateStore;
|
37 | 41 | import org.apache.accumulo.core.fate.Repo;
|
38 | 42 | import org.apache.accumulo.core.fate.StackOverflowException;
|
@@ -150,19 +154,8 @@ public FateId create() {
|
150 | 154 | }
|
151 | 155 |
|
152 | 156 | @Override
|
153 |
| - public Optional<FateId> seedTransaction(Fate.FateOperation fateOp, FateKey fateKey, |
154 |
| - Repo<T> repo, boolean autoCleanUp) { |
155 |
| - var optional = store.seedTransaction(fateOp, fateKey, repo, autoCleanUp); |
156 |
| - if (storeLog.isTraceEnabled()) { |
157 |
| - optional.ifPresentOrElse(fateId -> { |
158 |
| - storeLog.trace("{} seeded {} {} {}", fateId, fateKey, toLogString.apply(repo), |
159 |
| - autoCleanUp); |
160 |
| - }, () -> { |
161 |
| - storeLog.trace("Possibly unable to seed {} {} {}", fateKey, toLogString.apply(repo), |
162 |
| - autoCleanUp); |
163 |
| - }); |
164 |
| - } |
165 |
| - return optional; |
| 157 | + public Seeder<T> beginSeeding() { |
| 158 | + return new SeederLogger<>(store, toLogString); |
166 | 159 | }
|
167 | 160 |
|
168 | 161 | @Override
|
@@ -202,4 +195,41 @@ public void deleteDeadReservations() {
|
202 | 195 | }
|
203 | 196 | };
|
204 | 197 | }
|
| 198 | + |
| 199 | + public static class SeederLogger<T> implements Seeder<T> { |
| 200 | + private final FateStore<T> store; |
| 201 | + private final Seeder<T> seeder; |
| 202 | + private final Function<Repo<T>,String> toLogString; |
| 203 | + |
| 204 | + public SeederLogger(FateStore<T> store, Function<Repo<T>,String> toLogString) { |
| 205 | + this.store = Objects.requireNonNull(store); |
| 206 | + this.seeder = store.beginSeeding(); |
| 207 | + this.toLogString = Objects.requireNonNull(toLogString); |
| 208 | + } |
| 209 | + |
| 210 | + @Override |
| 211 | + public CompletableFuture<Optional<FateId>> attemptToSeedTransaction(FateOperation fateOp, |
| 212 | + FateKey fateKey, Repo<T> repo, boolean autoCleanUp) { |
| 213 | + var future = this.seeder.attemptToSeedTransaction(fateOp, fateKey, repo, autoCleanUp); |
| 214 | + return future.whenComplete((optional, throwable) -> { |
| 215 | + if (storeLog.isTraceEnabled()) { |
| 216 | + optional.ifPresentOrElse(fateId -> { |
| 217 | + storeLog.trace("{} seeded {} {} {}", fateId, fateKey, toLogString.apply(repo), |
| 218 | + autoCleanUp); |
| 219 | + }, () -> { |
| 220 | + storeLog.trace("Possibly unable to seed {} {} {}", fateKey, toLogString.apply(repo), |
| 221 | + autoCleanUp); |
| 222 | + }); |
| 223 | + } |
| 224 | + }); |
| 225 | + } |
| 226 | + |
| 227 | + @Override |
| 228 | + public void close() { |
| 229 | + seeder.close(); |
| 230 | + if (storeLog.isTraceEnabled()) { |
| 231 | + storeLog.trace("attempted to close seeder for {}", store.type()); |
| 232 | + } |
| 233 | + } |
| 234 | + } |
205 | 235 | }
|
0 commit comments