Skip to content
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-179: Added additional dirs required for live migration #163

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions conf/sidecar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cassandra_instances:
- id: 1
host: localhost1
port: 9042
cassandra_home_dir: ~/.ccm/test/node1
data_dirs:
- ~/.ccm/test/node1/data0
staging_dir: ~/.ccm/test/node1/sstable-staging
Expand All @@ -35,6 +36,7 @@ cassandra_instances:
- id: 2
host: localhost2
port: 9042
cassandra_home_dir: ~/.ccm/test/node2
data_dirs:
- ~/.ccm/test/node2/data0
staging_dir: ~/.ccm/test/node2/sstable-staging
Expand All @@ -47,6 +49,7 @@ cassandra_instances:
- id: 3
host: localhost3
port: 9042
cassandra_home_dir: ~/.ccm/test/node3
data_dirs:
- ~/.ccm/test/node3/data0
staging_dir: ~/.ccm/test/node3/sstable-staging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public interface InstanceMetadata
*/
int port();

/**
* @return the home directory of Cassandra instance
*/
String cassandraHomeDir();

/**
* @return a list of data directories of cassandra instance
*/
Expand All @@ -61,6 +66,26 @@ public interface InstanceMetadata
*/
String cdcDir();

/**
* @return commitlog directory of the cassandra instance
*/
@Nullable String commitlogDir();

/**
* @return hints directory of the cassandra instance
*/
@Nullable String hintsDir();

/**
* @return saved caches directory of the cassandra instance
*/
@Nullable String savedCachesDir();

/**
* @return local system data file directory of the cassandra instance
*/
@Nullable String localSystemDataFileDir();

/**
* @return a {@link CassandraAdapterDelegate} specific for the instance
*/
Expand All @@ -74,9 +99,10 @@ public interface InstanceMetadata

/**
* Get value from {@link CassandraAdapterDelegate}
*
* @param mapper the function is evaluated only when delegate is not null
* @param <T> value type
* @return value retrieved from {@link CassandraAdapterDelegate} or null
* @param <T> value type
*/
@Nullable
default <T> T applyFromDelegate(Function<CassandraAdapterDelegate, T> mapper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.apache.cassandra.sidecar.cluster.instance;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -30,19 +32,30 @@
import org.apache.cassandra.sidecar.metrics.instance.InstanceMetrics;
import org.apache.cassandra.sidecar.metrics.instance.InstanceMetricsImpl;
import org.apache.cassandra.sidecar.utils.FileUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Local implementation of InstanceMetadata.
*/
public class InstanceMetadataImpl implements InstanceMetadata
{
private static final String DEFAULT_CDC_RAW_DIR = "cdc_raw";
private static final String DEFAULT_COMMITLOG_DIR = "commitlog";
private static final String DEFAULT_HINTS_DIR = "hints";
private static final String DEFAULT_SAVED_CACHES_DIR = "saved_caches";

private final int id;
private final String host;
private final int port;
private final String cassandraHomeDir;
private final List<String> dataDirs;
private final String stagingDir;
private final String cdcDir;
private final String commitlogDir;
private final String hintsDir;
private final String savedCachesDir;
private final String localSystemDataFileDir;
@Nullable
private final CassandraAdapterDelegate delegate;
private final InstanceMetrics metrics;
Expand All @@ -52,15 +65,42 @@ protected InstanceMetadataImpl(Builder builder)
id = builder.id;
host = builder.host;
port = builder.port;
cassandraHomeDir = FileUtils.maybeResolveHomeDirectory(builder.cassandraHomeDir);
Path cassandraHomeDirPath = cassandraHomeDir == null ? null : Paths.get(cassandraHomeDir);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay with having cassandraHomeDir as a mandatory configuration? If yes, then I can push changes to make it mandatory. Assuming it is not mandatory for now.

dataDirs = builder.dataDirs.stream()
.map(FileUtils::maybeResolveHomeDirectory)
.collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
stagingDir = FileUtils.maybeResolveHomeDirectory(builder.stagingDir);
cdcDir = FileUtils.maybeResolveHomeDirectory(builder.cdcDir);
cdcDir = builder.cdcDir != null
? FileUtils.maybeResolveHomeDirectory(builder.cdcDir)
: cassandraHomeDirPath == null
? null
: cassandraHomeDirPath.resolve(DEFAULT_CDC_RAW_DIR).toAbsolutePath().toString();
commitlogDir = builder.commitlogDir != null
? FileUtils.maybeResolveHomeDirectory(builder.commitlogDir)
: cassandraHomeDirPath == null
? null
: cassandraHomeDirPath.resolve(DEFAULT_COMMITLOG_DIR).toAbsolutePath().toString();
hintsDir = builder.hintsDir != null
? FileUtils.maybeResolveHomeDirectory(builder.hintsDir)
: cassandraHomeDirPath == null
? null
: cassandraHomeDirPath.resolve(DEFAULT_HINTS_DIR).toAbsolutePath().toString();
savedCachesDir = builder.savedCachesDir != null
? FileUtils.maybeResolveHomeDirectory(builder.savedCachesDir)
: cassandraHomeDirPath == null
? null
: cassandraHomeDirPath.resolve(DEFAULT_SAVED_CACHES_DIR).toAbsolutePath().toString();
localSystemDataFileDir = FileUtils.maybeResolveHomeDirectory(builder.localSystemDataFileDir);
delegate = builder.delegate;
metrics = builder.metrics;
}

public static Builder builder()
{
return new Builder();
}

@Override
public int id()
{
Expand All @@ -79,6 +119,11 @@ public int port()
return port;
}

@Override
public String cassandraHomeDir()
{
return cassandraHomeDir;
}
@Override
public List<String> dataDirs()
{
Expand All @@ -98,20 +143,39 @@ public String cdcDir()
}

@Override
public @Nullable CassandraAdapterDelegate delegate()
public @Nullable String commitlogDir()
{
return delegate;
return commitlogDir;
}

@Override
public InstanceMetrics metrics()
public @Nullable String hintsDir()
{
return metrics;
return hintsDir;
}

public static Builder builder()
@Override
public @Nullable String savedCachesDir()
{
return new Builder();
return savedCachesDir;
}

@Override
public @Nullable String localSystemDataFileDir()
{
return localSystemDataFileDir;
}

@Override
public @Nullable CassandraAdapterDelegate delegate()
{
return delegate;
}

@Override
public @NotNull InstanceMetrics metrics()
{
return metrics;
}

/**
Expand All @@ -122,9 +186,14 @@ public static class Builder implements DataObjectBuilder<Builder, InstanceMetada
protected Integer id;
protected String host;
protected int port;
protected String cassandraHomeDir;
protected List<String> dataDirs;
protected String stagingDir;
protected String cdcDir;
protected String commitlogDir;
protected String hintsDir;
protected String savedCachesDir;
protected String localSystemDataFileDir;
protected CassandraAdapterDelegate delegate;
protected MetricRegistry metricRegistry;
protected InstanceMetrics metrics;
Expand All @@ -138,9 +207,14 @@ protected Builder(InstanceMetadataImpl instanceMetadata)
id = instanceMetadata.id;
host = instanceMetadata.host;
port = instanceMetadata.port;
cassandraHomeDir = instanceMetadata.cassandraHomeDir;
dataDirs = new ArrayList<>(instanceMetadata.dataDirs);
stagingDir = instanceMetadata.stagingDir;
cdcDir = instanceMetadata.cdcDir;
commitlogDir = instanceMetadata.commitlogDir;
hintsDir = instanceMetadata.hintsDir;
savedCachesDir = instanceMetadata.savedCachesDir;
localSystemDataFileDir = instanceMetadata.localSystemDataFileDir;
delegate = instanceMetadata.delegate;
metrics = instanceMetadata.metrics;
}
Expand Down Expand Up @@ -184,6 +258,17 @@ public Builder port(int port)
return update(b -> b.port = port);
}

/**
* Sets the {@code cassandraHomeDir} and returns a reference to this Builder enabling method chaining.
*
* @param cassandraHomeDir that {@code cassandraHomeDir} to set
* @return a reference to this Builder
*/
public Builder cassandraHomeDir(String cassandraHomeDir)
{
return update(b -> b.cassandraHomeDir = cassandraHomeDir);
}

/**
* Sets the {@code dataDirs} and returns a reference to this Builder enabling method chaining.
*
Expand Down Expand Up @@ -217,6 +302,50 @@ public Builder cdcDir(String cdcDir)
return update(b -> b.cdcDir = cdcDir);
}

/**
* Sets the {@code commitlogDir} and returns a reference to this Builder enabling method chaining.
*
* @param commitlogDir the {@code commitlogDir} to set
* @return a reference to this Builder
*/
public Builder commitlogDir(String commitlogDir)
{
return update(b -> b.commitlogDir = commitlogDir);
}

/**
* Sets the {@code hintsDir} and returns a reference to this Builder enabling method chaining.
*
* @param hintsDir the {@code hintsDir} to set
* @return a reference to this Builder
*/
public Builder hintsDir(String hintsDir)
{
return update(b -> b.hintsDir = hintsDir);
}

/**
* Sets the {@code savedCachesDir} and returns a reference to this Builder enabling method chaining.
*
* @param savedCachesDir the {@code savedCachesDir} to set
* @return a reference to this Builder
*/
public Builder savedCachesDir(String savedCachesDir)
{
return update(b -> b.savedCachesDir = savedCachesDir);
}

/**
* Sets the {@code localSystemDataFileDir} and return a reference to this Builder enabling method chaining.
*
* @param localSystemDataFileDir the {@code localSystemDataFileDir} to set
* @return a reference to this Builder
*/
public Builder localSystemDataFileDir(String localSystemDataFileDir)
{
return update(b -> b.localSystemDataFileDir = localSystemDataFileDir);
}

/**
* Sets the {@code delegate} and returns a reference to this Builder enabling method chaining.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public interface InstanceConfiguration
*/
int port();

/**
* @return Cassandra home directory of Cassandra instance
*/
String cassandraHomeDir();

/**
* @return a list of data directories of cassandra instance
*/
Expand All @@ -50,6 +55,26 @@ public interface InstanceConfiguration
*/
String stagingDir();

/**
* @return commitlog directory of cassandra instance
*/
String commitlogDir();

/**
* @return hints directory of cassandra instance
*/
String hintsDir();

/**
* @return saved caches directory of cassandra instance
*/
String savedCachesDir();

/**
* @return local system data file directory of cassandra instance
*/
String localSystemDataFileDir();

/**
* @return cdc directory of the cassandra instance
*/
Expand Down
Loading