This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cross Client Batching LeaderTimes - 2a] | Refactor coalescing leader…
…TimeGetter (#5120) * Fix tests + remove redundant tests * Refactor LeaderTimeGetter * Configurable bufferSize * Implement LeaderTimeCoalescingBatcher * Wire LeaderTimeGetter * Fix build * Address comments * Remove redundant line * Fix tests * Add generated changelog entries * Fix nits
- Loading branch information
1 parent
b7e72e7
commit 8ec6288
Showing
10 changed files
with
213 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
type: improvement | ||
improvement: | ||
description: '```LeaderTimeGetter``` is an interface responsible for making ```leaderTime``` | ||
requests to TimeLock with the intend of adding a client side request batching | ||
layer. TimeLock adaptor on AtlasDB client now accepts custom implementation of | ||
the same.' | ||
links: | ||
- https://github.com/palantir/atlasdb/pull/5120 |
63 changes: 63 additions & 0 deletions
63
lock-api/src/main/java/com/palantir/lock/client/LeaderTimeCoalescingBatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* (c) Copyright 2020 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.lock.client; | ||
|
||
import com.palantir.atlasdb.autobatch.Autobatchers; | ||
import com.palantir.atlasdb.autobatch.CoalescingRequestFunction; | ||
import com.palantir.atlasdb.autobatch.DisruptorAutobatcher; | ||
import com.palantir.atlasdb.futures.AtlasFutures; | ||
import com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService; | ||
import com.palantir.atlasdb.timelock.api.Namespace; | ||
import com.palantir.lock.v2.LeaderTime; | ||
import com.palantir.tokens.auth.AuthHeader; | ||
import java.util.Map; | ||
import java.util.OptionalInt; | ||
import java.util.Set; | ||
|
||
public class LeaderTimeCoalescingBatcher implements AutoCloseable { | ||
private static final AuthHeader AUTH_HEADER = AuthHeader.valueOf("Bearer omitted"); | ||
private final DisruptorAutobatcher<Namespace, LeaderTime> batcher; | ||
|
||
public LeaderTimeCoalescingBatcher(MultiClientConjureTimelockService delegate, OptionalInt bufferSize) { | ||
this.batcher = Autobatchers.coalescing(new LeaderTimeCoalescingConsumer(delegate)) | ||
.bufferSize(bufferSize) | ||
.safeLoggablePurpose("get-leader-times") | ||
.build(); | ||
} | ||
|
||
public LeaderTime apply(Namespace namespace) { | ||
return AtlasFutures.getUnchecked(batcher.apply(namespace)); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
batcher.close(); | ||
} | ||
|
||
static class LeaderTimeCoalescingConsumer implements CoalescingRequestFunction<Namespace, LeaderTime> { | ||
private final MultiClientConjureTimelockService delegate; | ||
|
||
public LeaderTimeCoalescingConsumer(MultiClientConjureTimelockService delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public Map<Namespace, LeaderTime> apply(Set<Namespace> namespaces) { | ||
return delegate.leaderTimes(AUTH_HEADER, namespaces).getLeaderTimes(); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
lock-api/src/main/java/com/palantir/lock/client/LeaderTimeGetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* (c) Copyright 2020 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.lock.client; | ||
|
||
import com.palantir.lock.v2.LeaderTime; | ||
|
||
public interface LeaderTimeGetter extends AutoCloseable { | ||
LeaderTime leaderTime(); | ||
|
||
@Override | ||
void close(); | ||
} |
36 changes: 36 additions & 0 deletions
36
lock-api/src/main/java/com/palantir/lock/client/LegacyLeaderTimeGetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* (c) Copyright 2020 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.lock.client; | ||
|
||
import com.palantir.common.concurrent.CoalescingSupplier; | ||
import com.palantir.lock.v2.LeaderTime; | ||
|
||
public class LegacyLeaderTimeGetter implements LeaderTimeGetter { | ||
private final CoalescingSupplier<LeaderTime> time; | ||
|
||
public LegacyLeaderTimeGetter(NamespacedConjureTimelockService delegate) { | ||
this.time = new CoalescingSupplier<>(delegate::leaderTime); | ||
} | ||
|
||
@Override | ||
public LeaderTime leaderTime() { | ||
return time.get(); | ||
} | ||
|
||
@Override | ||
public void close() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
lock-api/src/main/java/com/palantir/lock/client/NamespacedCoalescingLeaderTimeGetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* (c) Copyright 2020 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.lock.client; | ||
|
||
import com.palantir.atlasdb.timelock.api.Namespace; | ||
import com.palantir.lock.v2.LeaderTime; | ||
|
||
/** | ||
* This class maintains the context of namespace for a client and directs leaderTime requests to | ||
* {@link LeaderTimeCoalescingBatcher} that coalesces and batches requests across clients. | ||
* | ||
* This is different from {@link LegacyLeaderTimeGetter} in that LegacyLeaderTimeGetter coalesces requests only for a | ||
* single namespace. | ||
*/ | ||
public class NamespacedCoalescingLeaderTimeGetter implements LeaderTimeGetter { | ||
private final LeaderTimeCoalescingBatcher batcher; | ||
private final Namespace namespace; | ||
|
||
public NamespacedCoalescingLeaderTimeGetter(String namespace, LeaderTimeCoalescingBatcher batcher) { | ||
this.namespace = Namespace.of(namespace); | ||
this.batcher = batcher; | ||
} | ||
|
||
@Override | ||
public LeaderTime leaderTime() { | ||
return batcher.apply(namespace); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
batcher.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters