-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CASSSIDECAR-162: Sidecar endpoint to GET sstable's preemptive interval value #152
base: trunk
Are you sure you want to change the base?
Changes from all commits
1aafa61
e33ccad
de16561
456caa4
a27b56f
9ae9912
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,4 +159,10 @@ public interface StorageJmxOperations | |
* @throws InterruptedException it does not really throw but declared in MBean | ||
*/ | ||
int forceKeyspaceCleanup(int jobs, String keyspaceName, String... tables) throws IOException, ExecutionException, InterruptedException; | ||
|
||
/** | ||
* Invokes C* StorageServiceMBean's JMX function getSSTablePreemptiveOpenIntervalInMB | ||
* @return the same value returned by the JMX operation | ||
*/ | ||
int getSSTablePreemptiveOpenIntervalInMB(); | ||
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. This is the only place we use 'inMB', this should exactly match C* JMX function name |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,11 @@ public final class ApiEndpointsV1 | |
|
||
public static final String CONNECTED_CLIENT_STATS_ROUTE = API_V1 + CASSANDRA + "/stats/connected-clients"; | ||
|
||
// Endpoint to retrieve sstable's preemptiveOpenInterval value. | ||
// Value returned is in MB, may return negative value when disabled | ||
private static final String SSTABLE = "/sstable"; | ||
public static final String SSTABLE_PREEMPTIVE_OPEN_INTERVAL_ROUTE = API_V1 + CASSANDRA + SSTABLE + | ||
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. I know we are reusing the
That would make us have to modify the response to something like:
What do you think? 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.
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. I did explore this a little, I believe the one you suggested /preemptive-open-interval?unit=mb is more easy way to implement and also is in-line with current JMX call semantics. Other alternatives unnecessarily complicates conversions from human readable format to byte size at the client. 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. Added unit=MiB param, unit names matches with names C* is using. |
||
"/preemptive-open-interval"; | ||
private ApiEndpointsV1() | ||
{ | ||
throw new IllegalStateException(getClass() + " is a constants container and shall not be instantiated"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.cassandra.sidecar.common.request; | ||
|
||
import io.netty.handler.codec.http.HttpMethod; | ||
import org.apache.cassandra.sidecar.common.ApiEndpointsV1; | ||
import org.apache.cassandra.sidecar.common.response.GetPreemptiveOpenIntervalResponse; | ||
|
||
/** | ||
* Request to get preemptive open interval value | ||
*/ | ||
public class GetPreemptiveOpenIntervalRequest extends JsonRequest<GetPreemptiveOpenIntervalResponse> | ||
{ | ||
/** | ||
* Constructs a request to GET preemptive open interval value | ||
*/ | ||
public GetPreemptiveOpenIntervalRequest() | ||
{ | ||
super(ApiEndpointsV1.SSTABLE_PREEMPTIVE_OPEN_INTERVAL_ROUTE); | ||
} | ||
|
||
/** | ||
* Constructs a request to GET preemptive open interval value with query param 'unit' | ||
* @param unit query param, data storage units of preemptive open interval value | ||
*/ | ||
public GetPreemptiveOpenIntervalRequest(String unit) | ||
{ | ||
super(ApiEndpointsV1.SSTABLE_PREEMPTIVE_OPEN_INTERVAL_ROUTE + "?unit=" + unit); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public HttpMethod method() | ||
{ | ||
return HttpMethod.GET; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.cassandra.sidecar.common.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* Response for GET preemptive open interval API | ||
*/ | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class GetPreemptiveOpenIntervalResponse | ||
{ | ||
private final int sstablePreemptiveOpenInterval; | ||
|
||
/** | ||
* Constructs a response with preemptive open interval value | ||
* @param sstablePreemptiveOpenInterval value of preemptive open interval | ||
*/ | ||
public GetPreemptiveOpenIntervalResponse(@JsonProperty("SSTablePreemptiveOpenInterval") int sstablePreemptiveOpenInterval) | ||
{ | ||
this.sstablePreemptiveOpenInterval = sstablePreemptiveOpenInterval; | ||
} | ||
|
||
@JsonProperty("SSTablePreemptiveOpenInterval") | ||
public int sstablePreemptiveOpenInterval() | ||
{ | ||
return sstablePreemptiveOpenInterval; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.apache.cassandra.sidecar.common.server; | ||
|
||
/** | ||
* Enum for data storage units, resembles same unit names as C* is using | ||
*/ | ||
public enum DataStorageUnit | ||
{ | ||
BYTES("B"), | ||
KIBIBYTES("KiB"), | ||
MEBIBYTES("MiB"), | ||
GIBIBYTES("GiB"); | ||
|
||
private final String unit; | ||
|
||
DataStorageUnit(String unit) | ||
{ | ||
this.unit = unit; | ||
} | ||
|
||
public String getValue() | ||
{ | ||
return unit; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
import org.apache.cassandra.sidecar.cluster.CassandraAdapterDelegate; | ||
import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata; | ||
import org.apache.cassandra.sidecar.common.server.MetricsOperations; | ||
import org.apache.cassandra.sidecar.common.server.StorageOperations; | ||
import org.apache.cassandra.sidecar.common.server.data.Name; | ||
import org.apache.cassandra.sidecar.common.server.data.QualifiedTableName; | ||
import org.apache.cassandra.sidecar.common.server.exceptions.JmxAuthenticationException; | ||
|
@@ -331,4 +332,16 @@ public static String extractHostAddressWithoutPort(String address) | |
} | ||
return address; | ||
} | ||
|
||
protected StorageOperations getStorageOperations(String host) | ||
{ | ||
CassandraAdapterDelegate delegate = this.metadataFetcher.delegate(host); | ||
StorageOperations storageOperations = delegate == null ? null : delegate.storageOperations(); | ||
if (storageOperations == null) | ||
{ | ||
throw cassandraServiceUnavailable(); | ||
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. Do we want to add some text to this error? 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. cassandraServiceUnavailable currently says "Cassandra service is unavailable". The same message goes back in client's response. As this is an internal error, adding further info may leak internal info to the client. We use the same cassandraServiceUnavailable almost everywhere without adding further details, must be the same reason I am assuming. Any other kind of exception is caught in AbstractHandler's handle() and logged and updated in the response. |
||
} | ||
|
||
return storageOperations; | ||
} | ||
} |
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.
Removed 'inMB' from StorageOperations function names to make them generic for supporting other units later on.