mirror of https://github.com/apache/cassandra
Follow-up to CASSANDRA-8143
stops Schema initializing tables in client mode patch by Branimir Lambov; reviewed by Aleksey Yeschenko for CASSANDRA-8143
This commit is contained in:
parent
762b48f2de
commit
a29d206532
|
|
@ -91,8 +91,11 @@ public class Schema
|
|||
*/
|
||||
public Schema()
|
||||
{
|
||||
load(SchemaKeyspace.metadata());
|
||||
load(SystemKeyspace.metadata());
|
||||
if (!Config.isClientMode())
|
||||
{
|
||||
load(SchemaKeyspace.metadata());
|
||||
load(SystemKeyspace.metadata());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -581,7 +584,7 @@ public class Schema
|
|||
Keyspace.clear(ksm.name);
|
||||
clearKeyspaceMetadata(ksm);
|
||||
|
||||
keyspace.writeOrder.awaitNewBarrier();
|
||||
Keyspace.writeOrder.awaitNewBarrier();
|
||||
|
||||
// force a new segment in the CL
|
||||
CommitLog.instance.forceRecycleAllSegments(droppedCfs);
|
||||
|
|
|
|||
|
|
@ -370,6 +370,12 @@ public abstract class SSTableReader extends SSTable implements SelfRefCounted<SS
|
|||
return open(descriptor, components, cfs.metadata, false, false); // do not track hotness
|
||||
}
|
||||
|
||||
// use only for offline or "Standalone" operations
|
||||
public static SSTableReader openNoValidation(Descriptor descriptor, CFMetaData metadata) throws IOException
|
||||
{
|
||||
return open(descriptor, componentsFor(descriptor), metadata, false, false); // do not track hotness
|
||||
}
|
||||
|
||||
/**
|
||||
* Open SSTable reader to be used in batch mode(such as sstableloader).
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
* 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.io.sstable.format;
|
||||
|
||||
import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.google.common.util.concurrent.Runnables;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.cassandra.concurrent.ScheduledExecutors;
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.Config;
|
||||
import org.apache.cassandra.db.filter.ColumnFilter;
|
||||
import org.apache.cassandra.db.marshal.BytesType;
|
||||
import org.apache.cassandra.db.rows.SliceableUnfilteredRowIterator;
|
||||
import org.apache.cassandra.dht.ByteOrderedPartitioner;
|
||||
import org.apache.cassandra.exceptions.ConfigurationException;
|
||||
import org.apache.cassandra.io.sstable.Descriptor;
|
||||
import org.apache.cassandra.io.sstable.format.SSTableFormat;
|
||||
import org.apache.cassandra.io.sstable.format.SSTableReader;
|
||||
import org.apache.cassandra.io.sstable.format.Version;
|
||||
|
||||
/**
|
||||
* Tests backwards compatibility for SSTables
|
||||
*/
|
||||
public class ClientModeSSTableTest
|
||||
{
|
||||
public static final String LEGACY_SSTABLE_PROP = "legacy-sstable-root";
|
||||
public static final String KSNAME = "Keyspace1";
|
||||
public static final String CFNAME = "Standard1";
|
||||
|
||||
public static File LEGACY_SSTABLE_ROOT;
|
||||
|
||||
static CFMetaData metadata;
|
||||
|
||||
@BeforeClass
|
||||
public static void defineSchema() throws ConfigurationException
|
||||
{
|
||||
Config.setClientMode(true);
|
||||
|
||||
metadata = CFMetaData.Builder.createDense(KSNAME, CFNAME, false, false)
|
||||
.addPartitionKey("key", BytesType.instance)
|
||||
.addClusteringColumn("column", BytesType.instance)
|
||||
.addRegularColumn("value", BytesType.instance)
|
||||
.withPartitioner(ByteOrderedPartitioner.instance)
|
||||
.build();
|
||||
|
||||
String scp = System.getProperty(LEGACY_SSTABLE_PROP);
|
||||
assert scp != null;
|
||||
LEGACY_SSTABLE_ROOT = new File(scp).getAbsoluteFile();
|
||||
assert LEGACY_SSTABLE_ROOT.isDirectory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a descriptor for the legacy sstable at the given version.
|
||||
*/
|
||||
protected Descriptor getDescriptor(String ver)
|
||||
{
|
||||
File directory = new File(LEGACY_SSTABLE_ROOT + File.separator + ver + File.separator + KSNAME);
|
||||
return new Descriptor(ver, directory, KSNAME, CFNAME, 0, SSTableFormat.Type.LEGACY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVersions() throws Throwable
|
||||
{
|
||||
boolean notSkipped = false;
|
||||
|
||||
for (File version : LEGACY_SSTABLE_ROOT.listFiles())
|
||||
{
|
||||
if (!new File(LEGACY_SSTABLE_ROOT + File.separator + version.getName() + File.separator + KSNAME).isDirectory())
|
||||
continue;
|
||||
if (Version.validate(version.getName()) && SSTableFormat.Type.LEGACY.info.getVersion(version.getName()).isCompatible())
|
||||
{
|
||||
notSkipped = true;
|
||||
testVersion(version.getName());
|
||||
}
|
||||
}
|
||||
|
||||
assert notSkipped;
|
||||
}
|
||||
|
||||
public void testVersion(String version) throws Throwable
|
||||
{
|
||||
SSTableReader reader = null;
|
||||
try
|
||||
{
|
||||
reader = SSTableReader.openNoValidation(getDescriptor(version), metadata);
|
||||
|
||||
ByteBuffer key = bytes(Integer.toString(100));
|
||||
|
||||
try (SliceableUnfilteredRowIterator iter = reader.iterator(metadata.decorateKey(key), ColumnFilter.selection(metadata.partitionColumns()), false, false))
|
||||
{
|
||||
assert iter.next().clustering().get(0).equals(key);
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
System.err.println("Failed to read " + version);
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (reader != null)
|
||||
{
|
||||
int globalTidyCount = SSTableReader.GlobalTidy.lookup.size();
|
||||
reader.selfRef().release();
|
||||
assert reader.selfRef().globalCount() == 0;
|
||||
|
||||
// await clean-up to complete if started.
|
||||
ScheduledExecutors.nonPeriodicTasks.submit(Runnables.doNothing()).get();
|
||||
// Ensure clean-up completed.
|
||||
assert SSTableReader.GlobalTidy.lookup.size() < globalTidyCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue