Skip to content

Commit

Permalink
Fix offline tools startup
Browse files Browse the repository at this point in the history
  • Loading branch information
blambov committed Oct 29, 2021
1 parent f835fb5 commit 4bb162a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2899,7 +2899,7 @@ public static Float getMemtableCleanupThreshold()

public static Map<String, String> getMemtableOptions()
{
return conf.memtable;
return conf != null ? conf.memtable : null;
}

public static int getIndexSummaryResizeIntervalInMinutes()
Expand Down
8 changes: 6 additions & 2 deletions src/java/org/apache/cassandra/db/ColumnFamilyStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,14 @@ public ColumnFamilyStore(Keyspace keyspace,

logger.info("Initializing {}.{}", keyspace.getName(), name);

// Create Memtable only on online
// Create Memtable and its metrics object only on online
Memtable initialMemtable = null;
TableMetrics.ReleasableMetric memtableMetrics = null;
if (DatabaseDescriptor.isDaemonInitialized())
{
initialMemtable = createMemtable(new AtomicReference<>(CommitLog.instance.getCurrentPosition()));
memtableMetrics = memtableFactory.createMemtableMetrics(metadata);
}
data = new Tracker(this, initialMemtable, loadSSTables);

// Note that this needs to happen before we load the first sstables, or the global sstable tracker will not
Expand Down Expand Up @@ -428,7 +432,7 @@ public ColumnFamilyStore(Keyspace keyspace,
indexManager.addIndex(info, true);
}

metric = new TableMetrics(this, memtableFactory.createMemtableMetrics(metadata));
metric = new TableMetrics(this, memtableMetrics);

if (data.loadsstables)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class SkipListMemtable extends AbstractAllocatorMemtable
{
private static final Logger logger = LoggerFactory.getLogger(SkipListMemtable.class);

public static final Factory FACTORY = SkipListMemtable::new;
public static final Factory FACTORY = SkipListMemtableFactory.INSTANCE;

private static final int ROW_OVERHEAD_HEAP_SIZE;
static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,20 @@
import org.apache.cassandra.schema.TableMetadataRef;

/**
* This class exists solely to avoid initialization of the default memtable class.
* Some tests want to setup table parameters before initializing DatabaseDescriptor -- this allows them to do so.
* This class makes better sense as an inner class to SkipListMemtable (which could be as simple as
* FACTORY = SkipListMemtable::new), but having it there causes the SkipListMemtable class to be initialized the first
* time it is referenced (e.g. during default memtable factory construction).
*
* Some tests want to setup table parameters before initializing DatabaseDescriptor -- this allows them to do so, and
* also makes sure the memtable memory pools are not created for offline tools.
*/
public class DefaultMemtableFactory implements Memtable.Factory
public class SkipListMemtableFactory implements Memtable.Factory
{
@Override
public Memtable create(AtomicReference<CommitLogPosition> commitLogLowerBound, TableMetadataRef metadaRef, Memtable.Owner owner)
{
return SkipListMemtable.FACTORY.create(commitLogLowerBound, metadaRef, owner);
}

@Override
public boolean writesShouldSkipCommitLog()
{
return SkipListMemtable.FACTORY.writesShouldSkipCommitLog();
}

@Override
public boolean writesAreDurable()
{
return SkipListMemtable.FACTORY.writesAreDurable();
}

@Override
public boolean streamToMemtable()
{
return SkipListMemtable.FACTORY.streamToMemtable();
}

@Override
public boolean streamFromMemtable()
{
return SkipListMemtable.FACTORY.streamFromMemtable();
return new SkipListMemtable(commitLogLowerBound, metadaRef, owner);
}

@Override
public TableMetrics.ReleasableMetric createMemtableMetrics(TableMetadataRef metadataRef)
{
return SkipListMemtable.FACTORY.createMemtableMetrics(metadataRef);
}
public static final SkipListMemtableFactory INSTANCE = new SkipListMemtableFactory();
}
4 changes: 2 additions & 2 deletions src/java/org/apache/cassandra/schema/MemtableParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.google.common.collect.ImmutableMap;

import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.memtable.DefaultMemtableFactory;
import org.apache.cassandra.db.memtable.SkipListMemtableFactory;
import org.apache.cassandra.db.memtable.Memtable;
import org.apache.cassandra.exceptions.ConfigurationException;

Expand Down Expand Up @@ -60,7 +60,7 @@ public String toString()
private MemtableParams()
{
this.options = ImmutableMap.of();
this.factory = new DefaultMemtableFactory();
this.factory = SkipListMemtableFactory.INSTANCE;
}

public MemtableParams(Map<String, String> options)
Expand Down

0 comments on commit 4bb162a

Please sign in to comment.