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
Feature/qos service api #2629
Merged
+14,065
−708
Merged
Feature/qos service api #2629
Changes from 20 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
f5664a2
Extremely basic QosServiceResource
gsheasby 6beb734
Make resource an interface
gsheasby 45cc7fc
Add client PathParam
gsheasby f0345e9
Clean up javax.ws.rs dependencies
gsheasby 013582c
Create stub for AtlasDbQosClient
gsheasby a303b1e
Calls to checkLimit use up a credit; throw when out of credits
gsheasby 139a208
Add QosServiceResourceImpl + test
gsheasby fb925d3
AutoDelegate for Cassandra.Client
gsheasby 50cc876
Rename QosService stuff
gsheasby bcbde47
Pass AtlasDbQosClient to CassandraClient
gsheasby 9be8291
Check limit on multiget_slice
gsheasby e2efe14
Check limit on batch_mutate
gsheasby 47de8d5
Don't test we aren't soft-limited while we can never be soft-limited
gsheasby c7cfa3d
Check limit on remaining CassandraClient methods
gsheasby d5fa2db
Scheduled refresh of AtlasDbQosClient.credits
gsheasby 9666ee0
Refresh every second
gsheasby 7717ee4
Mount qos-service on Timelock
hsaraogi db0037b
Checkstyle
hsaraogi 5ccf451
Update dependency locks
gsheasby c191cb7
Merge branch 'develop' into feature/qos-service-api
hsaraogi 364ae22
Dont throw limitExceededException
hsaraogi 5515d31
Move client param around
hsaraogi 32ed6bc
Comment
hsaraogi ffa5e5a
Qos Service config (#2644)
hsaraogi f8d687f
[QoS] qos ete test (#2652)
nziebart 1613da4
[QoS] rate limiter (#2653)
nziebart 3873586
[QoS] Feature/qos client (#2650)
hsaraogi 103fd97
deps
22b1e7a
fix tests
3d1f43f
[QoS] Feature/qos meters (#2640)
hsaraogi 3797765
[QoS] QosClient with ratelimiter (#2667)
hsaraogi 509f3e9
locks
hsaraogi 34dcd28
[QoS] Create a jaxrs-client for the integ tests (#2675)
hsaraogi b8f8312
Nziebart/merge develop into qos (#2683)
nziebart 4fcef06
qos rate limiting (#2709)
fsamuel-bs d0b9ae0
[QoS] Estimate the number of read bytes w/ number of rows (#2717)
fsamuel-bs 8998354
weight estimates (#2725)
nziebart bbd272e
[QoS] Fix exceptions thrown on CqlExecutor (#2696)
fsamuel-bs d2d7b18
[QoS] Qos ete test (#2708)
hsaraogi be45487
[QoS] Fix/qos system table rate limiting (#2739)
hsaraogi bf251e1
Merge develop to the feature branch (#2741)
hsaraogi 11192dd
Nziebart/cell timestamps qos (#2745)
nziebart d4c2c67
Merge branch 'develop' into feature/qos-service-api
hsaraogi ae1a3d5
Differentiate between read and write limits when logging (#2751)
hsaraogi b5caa16
Merge branch 'develop' into feature/qos-service-api
nziebart da8e513
Use longs in the rate limiter and handle negative adjustments. (#2758)
hsaraogi 92aa59c
Merge branch 'develop' into feature/qos-service-api
hsaraogi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
104 changes: 104 additions & 0 deletions
104
atlasdb-cassandra/src/main/java/com/palantir/atlasdb/keyvalue/cassandra/CassandraClient.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,104 @@ | ||
/* | ||
* Copyright 2017 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the BSD-3 License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* 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.atlasdb.keyvalue.cassandra; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.Callable; | ||
|
||
import org.apache.cassandra.thrift.AutoDelegate_Client; | ||
import org.apache.cassandra.thrift.Cassandra; | ||
import org.apache.cassandra.thrift.ColumnOrSuperColumn; | ||
import org.apache.cassandra.thrift.ColumnParent; | ||
import org.apache.cassandra.thrift.Compression; | ||
import org.apache.cassandra.thrift.ConsistencyLevel; | ||
import org.apache.cassandra.thrift.CqlResult; | ||
import org.apache.cassandra.thrift.InvalidRequestException; | ||
import org.apache.cassandra.thrift.KeyRange; | ||
import org.apache.cassandra.thrift.KeySlice; | ||
import org.apache.cassandra.thrift.Mutation; | ||
import org.apache.cassandra.thrift.SchemaDisagreementException; | ||
import org.apache.cassandra.thrift.SlicePredicate; | ||
import org.apache.cassandra.thrift.TimedOutException; | ||
import org.apache.cassandra.thrift.UnavailableException; | ||
import org.apache.thrift.TException; | ||
|
||
import com.palantir.atlasdb.qos.AtlasDbQosClient; | ||
import com.palantir.common.base.Throwables; | ||
import com.palantir.processors.AutoDelegate; | ||
|
||
/** | ||
* Wrapper for Cassandra.Client. | ||
*/ | ||
@AutoDelegate(typeToExtend = Cassandra.Client.class) | ||
@SuppressWarnings({"checkstyle:all", "DuplicateThrows"}) // :'( | ||
public class CassandraClient extends AutoDelegate_Client { | ||
private final Cassandra.Client delegate; | ||
private final AtlasDbQosClient qosClient; | ||
|
||
public CassandraClient(Cassandra.Client delegate, AtlasDbQosClient qosClient) { | ||
super(delegate.getInputProtocol()); | ||
this.delegate = delegate; | ||
this.qosClient = qosClient; | ||
} | ||
|
||
@Override | ||
public Cassandra.Client delegate() { | ||
return delegate; | ||
} | ||
|
||
@Override | ||
public Map<ByteBuffer, List<ColumnOrSuperColumn>> multiget_slice(List<ByteBuffer> keys, ColumnParent column_parent, | ||
SlicePredicate predicate, ConsistencyLevel consistency_level) | ||
throws InvalidRequestException, UnavailableException, TimedOutException, TException { | ||
return checkLimitAndCall(() -> super.multiget_slice(keys, column_parent, predicate, consistency_level)); | ||
} | ||
|
||
@Override | ||
public void batch_mutate(Map<ByteBuffer, Map<String, List<Mutation>>> mutation_map, | ||
ConsistencyLevel consistency_level) | ||
throws InvalidRequestException, UnavailableException, TimedOutException, TException { | ||
checkLimitAndCall(() -> { | ||
super.batch_mutate(mutation_map, consistency_level); | ||
return null; | ||
}); | ||
} | ||
|
||
@Override | ||
public CqlResult execute_cql3_query(ByteBuffer query, Compression compression, ConsistencyLevel consistency) | ||
throws InvalidRequestException, UnavailableException, TimedOutException, SchemaDisagreementException, | ||
TException { | ||
return checkLimitAndCall(() -> super.execute_cql3_query(query, compression, consistency)); | ||
} | ||
|
||
@Override | ||
public List<KeySlice> get_range_slices(ColumnParent column_parent, SlicePredicate predicate, KeyRange range, | ||
ConsistencyLevel consistency_level) | ||
throws InvalidRequestException, UnavailableException, TimedOutException, TException { | ||
return checkLimitAndCall(() -> super.get_range_slices(column_parent, predicate, range, consistency_level)); | ||
} | ||
|
||
private <T> T checkLimitAndCall(Callable<T> callable) { | ||
try { | ||
qosClient.checkLimit(); | ||
return callable.call(); | ||
} catch (Exception ex) { | ||
throw Throwables.throwUncheckedException(ex); | ||
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. we probably dont want to wrap these exceptions 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. Fixed. |
||
} | ||
} | ||
} |
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
94 changes: 94 additions & 0 deletions
94
...-cassandra/src/test/java/com/palantir/atlasdb/keyvalue/cassandra/CassandraClientTest.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,94 @@ | ||
/* | ||
* Copyright 2017 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the BSD-3 License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* 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.atlasdb.keyvalue.cassandra; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import javax.naming.LimitExceededException; | ||
|
||
import org.apache.cassandra.thrift.Cassandra; | ||
import org.apache.cassandra.thrift.ColumnParent; | ||
import org.apache.cassandra.thrift.Compression; | ||
import org.apache.cassandra.thrift.ConsistencyLevel; | ||
import org.apache.cassandra.thrift.KeyRange; | ||
import org.apache.cassandra.thrift.SlicePredicate; | ||
import org.apache.thrift.TException; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.palantir.atlasdb.encoding.PtBytes; | ||
import com.palantir.atlasdb.keyvalue.cassandra.thrift.SlicePredicates; | ||
import com.palantir.atlasdb.qos.AtlasDbQosClient; | ||
|
||
public class CassandraClientTest { | ||
private static final ByteBuffer ROW_KEY = ByteBuffer.wrap(PtBytes.toBytes("key")); | ||
|
||
private final Cassandra.Client mockClient = mock(Cassandra.Client.class); | ||
private final AtlasDbQosClient qosClient = mock(AtlasDbQosClient.class); | ||
|
||
private static final ColumnParent TEST_TABLE = new ColumnParent("table"); | ||
private static final SlicePredicate SLICE_PREDICATE = SlicePredicates.create(SlicePredicates.Range.ALL, | ||
SlicePredicates.Limit.ONE); | ||
|
||
private CassandraClient client; | ||
|
||
@Before | ||
public void setUp() { | ||
client = new CassandraClient(mockClient, qosClient); | ||
} | ||
|
||
@Test | ||
public void multigetSliceChecksLimit() throws TException, LimitExceededException { | ||
client.multiget_slice(ImmutableList.of(ROW_KEY), TEST_TABLE, SLICE_PREDICATE, ConsistencyLevel.ANY); | ||
|
||
verify(qosClient, times(1)).checkLimit(); | ||
verifyNoMoreInteractions(qosClient); | ||
} | ||
|
||
@Test | ||
public void batchMutateChecksLimit() throws TException, LimitExceededException { | ||
client.batch_mutate(ImmutableMap.of(), ConsistencyLevel.ANY); | ||
|
||
verify(qosClient, times(1)).checkLimit(); | ||
verifyNoMoreInteractions(qosClient); | ||
} | ||
|
||
@Test | ||
public void executeCqlQueryChecksLimit() throws TException, LimitExceededException { | ||
ByteBuffer query = ByteBuffer.wrap("SELECT * FROM test_table LIMIT 1".getBytes(StandardCharsets.UTF_8)); | ||
client.execute_cql3_query(query, Compression.NONE, ConsistencyLevel.ANY); | ||
|
||
verify(qosClient, times(1)).checkLimit(); | ||
verifyNoMoreInteractions(qosClient); | ||
} | ||
|
||
@Test | ||
public void getRangeSlicesChecksLimit() throws TException, LimitExceededException { | ||
client.get_range_slices(TEST_TABLE, SLICE_PREDICATE, new KeyRange(), ConsistencyLevel.ANY); | ||
|
||
verify(qosClient, times(1)).checkLimit(); | ||
verifyNoMoreInteractions(qosClient); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
what's the purpose of accepting a callable here? why not just
checkLimit()
before each call?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.
Got rid of this method.