-
Notifications
You must be signed in to change notification settings - Fork 38
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-220: Add CdcRawDirectorySpaceCleaner for tracking and cleaning up the cdc_… #203
Open
jberragan
wants to merge
2
commits into
apache:trunk
Choose a base branch
from
jberragan:CASSSIDECAR-220
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
82 changes: 82 additions & 0 deletions
82
server/src/main/java/org/apache/cassandra/sidecar/db/SystemViewsDatabaseAccessor.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,82 @@ | ||
/* | ||
* 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.db; | ||
|
||
import com.datastax.driver.core.BoundStatement; | ||
import com.datastax.driver.core.ResultSet; | ||
import com.datastax.driver.core.Row; | ||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
import org.apache.cassandra.sidecar.common.server.CQLSessionProvider; | ||
import org.apache.cassandra.sidecar.db.schema.SystemViewsSchema; | ||
import org.apache.cassandra.sidecar.exceptions.SchemaUnavailableException; | ||
import org.apache.cassandra.sidecar.utils.FileUtils; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Database Accessor that queries cassandra to get information maintained under system_auth keyspace. | ||
*/ | ||
@Singleton | ||
public class SystemViewsDatabaseAccessor extends DatabaseAccessor<SystemViewsSchema> | ||
{ | ||
static final String YAML_PROP_PREVIOUS = "cdc_total_space_in_mb"; | ||
static final String YAML_PROP_CURRENT = "cdc_total_space"; | ||
|
||
@Inject | ||
public SystemViewsDatabaseAccessor(SystemViewsSchema systemViewsSchema, | ||
CQLSessionProvider sessionProvider) | ||
{ | ||
super(systemViewsSchema, sessionProvider); | ||
} | ||
|
||
@Nullable | ||
public Long getCdcTotalSpaceSetting() throws SchemaUnavailableException | ||
{ | ||
// attempt to parse Cassandra v4.0 'cdc_total_space_in_mb' yaml prop | ||
String cdcTotalSpaceInMb = getSetting(YAML_PROP_PREVIOUS); | ||
if (cdcTotalSpaceInMb != null) | ||
{ | ||
return FileUtils.mbStringToBytes(cdcTotalSpaceInMb); | ||
} | ||
|
||
// otherwise parse current (v5.0+) 'cdc_total_space' yaml prop | ||
String storageStringToBytes = getSetting(YAML_PROP_CURRENT); | ||
if (storageStringToBytes != null) | ||
{ | ||
return FileUtils.storageStringToBytes(storageStringToBytes); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Load a setting value from the `system_views.settings` table. | ||
* | ||
* @param name name of setting | ||
* @return setting value for a given `name` loaded from the `system_views.settings` table. | ||
*/ | ||
@Nullable | ||
public String getSetting(String name) throws SchemaUnavailableException | ||
{ | ||
BoundStatement statement = tableSchema.selectSettings().bind(name); | ||
ResultSet result = execute(statement); | ||
Row row = result.one(); | ||
return row != null && !row.isNull(0) ? row.getString(0) : null; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
server/src/main/java/org/apache/cassandra/sidecar/db/schema/SystemViewsSchema.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,68 @@ | ||
/* | ||
* 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.db.schema; | ||
|
||
import com.datastax.driver.core.PreparedStatement; | ||
import com.datastax.driver.core.Session; | ||
import com.google.inject.Singleton; | ||
import org.apache.cassandra.sidecar.exceptions.SchemaUnavailableException; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Schema for getting information stored in system_views keyspace. | ||
*/ | ||
@Singleton | ||
public class SystemViewsSchema extends CassandraSystemTableSchema | ||
{ | ||
protected static final String SYSTEM_VIEWS_KEYSPACE_NAME = "system_views"; | ||
protected static final String SYSTEM_VIEWS_SETTINGS_TABLE_NAME = "settings"; | ||
private PreparedStatement selectSettings; | ||
|
||
@Override | ||
protected String keyspaceName() | ||
{ | ||
return SYSTEM_VIEWS_KEYSPACE_NAME; | ||
} | ||
|
||
@Override | ||
protected String tableName() | ||
{ | ||
return SYSTEM_VIEWS_SETTINGS_TABLE_NAME; | ||
} | ||
|
||
public PreparedStatement selectSettings() throws SchemaUnavailableException | ||
{ | ||
ensureSchemaAvailable(); | ||
return selectSettings; | ||
} | ||
|
||
@Override | ||
protected void prepareStatements(@NotNull Session session) | ||
{ | ||
this.selectSettings = session.prepare("SELECT value FROM system_views.settings WHERE name = ?"); | ||
} | ||
|
||
protected void ensureSchemaAvailable() throws SchemaUnavailableException | ||
{ | ||
if (selectSettings == null) | ||
{ | ||
throw new SchemaUnavailableException(keyspaceName(), tableName()); | ||
} | ||
} | ||
} |
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 do we mean by previous? Is this being deprecated? Maybe we should throw a deprecation warn if that's the case?
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.
cdc_total_space_in_mb
was removed in Cassandra and replaced withcdc_total_space
in v5.0+