diff --git a/lealone-cluster/src/main/java/org/lealone/cluster/config/ReadRepairDecision.java b/lealone-cluster/src/main/java/org/lealone/cluster/config/ReadRepairDecision.java deleted file mode 100644 index a1684b9f0..000000000 --- a/lealone-cluster/src/main/java/org/lealone/cluster/config/ReadRepairDecision.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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.lealone.cluster.config; - -public enum ReadRepairDecision { - NONE, - GLOBAL, - DC_LOCAL; -} diff --git a/lealone-cluster/src/main/java/org/lealone/cluster/config/Schema.java b/lealone-cluster/src/main/java/org/lealone/cluster/config/Schema.java deleted file mode 100644 index c3b43dcfe..000000000 --- a/lealone-cluster/src/main/java/org/lealone/cluster/config/Schema.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.lealone.cluster.config; - -import java.util.Collections; -import java.util.List; - -public class Schema { - public static final Schema instance = new Schema(); - - public List getNonSystemKeyspaces() { - return Collections.emptyList(); - } -} diff --git a/lealone-cluster/src/main/java/org/lealone/cluster/db/Keyspace.java b/lealone-cluster/src/main/java/org/lealone/cluster/db/Keyspace.java index 565b6a69f..f7093f8ea 100644 --- a/lealone-cluster/src/main/java/org/lealone/cluster/db/Keyspace.java +++ b/lealone-cluster/src/main/java/org/lealone/cluster/db/Keyspace.java @@ -1,31 +1,63 @@ +/* + * 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.lealone.cluster.db; +import java.util.HashMap; + import org.lealone.cluster.config.DatabaseDescriptor; +import org.lealone.cluster.exceptions.ConfigurationException; import org.lealone.cluster.locator.AbstractReplicationStrategy; - -public class Keyspace { - private static Keyspace INSTANCE = new Keyspace(); - - public static Keyspace open(String keyspaceName) { - return INSTANCE; - } - - public static Iterable all() { - return null; - } - - private final AbstractReplicationStrategy replicationStrategy; - - public Keyspace() { - //TODO 按表或按数据库配置 - replicationStrategy = DatabaseDescriptor.getDefaultReplicationStrategy(); +import org.lealone.cluster.service.StorageService; +import org.lealone.dbobject.Schema; +import org.lealone.dbobject.Schema.ReplicationPropertiesChangeListener; + +public class Keyspace implements ReplicationPropertiesChangeListener { + private static final Keyspace INSTANCE = new Keyspace(); + private static final HashMap replicationStrategys = new HashMap<>(); + private static final AbstractReplicationStrategy defaultReplicationStrategy = DatabaseDescriptor + .getDefaultReplicationStrategy(); + + public static AbstractReplicationStrategy getReplicationStrategy(Schema schema) { + if (schema.getReplicationProperties() == null) + return defaultReplicationStrategy; + AbstractReplicationStrategy replicationStrategy = replicationStrategys.get(schema); + if (replicationStrategy == null) { + HashMap map = new HashMap<>(schema.getReplicationProperties()); + String className = map.remove("class"); + if (className == null) { + throw new ConfigurationException("Missing replication strategy class"); + } + + replicationStrategy = AbstractReplicationStrategy.createReplicationStrategy(schema.getFullName(), + AbstractReplicationStrategy.getClass(className), StorageService.instance.getTokenMetaData(), + DatabaseDescriptor.getEndpointSnitch(), map); + schema.setReplicationPropertiesChangeListener(INSTANCE); + replicationStrategys.put(schema, replicationStrategy); + } + return replicationStrategy; } - public AbstractReplicationStrategy getReplicationStrategy() { - return replicationStrategy; + private Keyspace() { } - public String getName() { - return null; + @Override + public void replicationPropertiesChanged(Schema schema) { + replicationStrategys.remove(schema); + getReplicationStrategy(schema); } } diff --git a/lealone-cluster/src/main/java/org/lealone/cluster/router/P2PRouter.java b/lealone-cluster/src/main/java/org/lealone/cluster/router/P2PRouter.java index 2dc1e50e1..b7b768949 100644 --- a/lealone-cluster/src/main/java/org/lealone/cluster/router/P2PRouter.java +++ b/lealone-cluster/src/main/java/org/lealone/cluster/router/P2PRouter.java @@ -49,6 +49,7 @@ import org.lealone.command.router.Router; import org.lealone.command.router.SerializedResult; import org.lealone.command.router.SortedResult; +import org.lealone.dbobject.Schema; import org.lealone.dbobject.table.TableFilter; import org.lealone.message.DbException; import org.lealone.result.ResultInterface; @@ -110,9 +111,7 @@ public int executeMerge(Merge merge) { private static int executeInsertOrMerge(InsertOrMerge iom) { final String localDataCenter = DatabaseDescriptor.getEndpointSnitch() .getDatacenter(Utils.getBroadcastAddress()); - String keyspaceName = iom.getTable().getSchema().getName(); - //AbstractReplicationStrategy rs = Keyspace.open(keyspaceName).getReplicationStrategy(); - + Schema schema = iom.getTable().getSchema(); List localRows = null; Map> localDataCenterRows = null; Map> remoteDataCenterRows = null; @@ -124,9 +123,9 @@ private static int executeInsertOrMerge(InsertOrMerge iom) { if (partitionKey == null) partitionKey = ValueUuid.getNewRandom(); Token tk = StorageService.getPartitioner().getToken(ByteBuffer.wrap(partitionKey.getBytesNoCopy())); - List naturalEndpoints = StorageService.instance.getNaturalEndpoints(keyspaceName, tk); + List naturalEndpoints = StorageService.instance.getNaturalEndpoints(schema, tk); Collection pendingEndpoints = StorageService.instance.getTokenMetaData().pendingEndpointsFor( - tk, keyspaceName); + tk, schema.getFullName()); Iterable targets = Iterables.concat(naturalEndpoints, pendingEndpoints); for (InetAddress destination : targets) { @@ -350,11 +349,11 @@ private static List getTargetEndpointsIfEqual(TableFilter tableFilt Value endPK = getPartitionKey(endRow); if (startPK != null && endPK != null && startPK == endPK) { - String keyspaceName = tableFilter.getTable().getSchema().getName(); + Schema schema = tableFilter.getTable().getSchema(); Token tk = StorageService.getPartitioner().getToken(ByteBuffer.wrap(startPK.getBytesNoCopy())); - List naturalEndpoints = StorageService.instance.getNaturalEndpoints(keyspaceName, tk); + List naturalEndpoints = StorageService.instance.getNaturalEndpoints(schema, tk); Collection pendingEndpoints = StorageService.instance.getTokenMetaData().pendingEndpointsFor( - tk, keyspaceName); + tk, schema.getFullName()); naturalEndpoints.addAll(pendingEndpoints); return naturalEndpoints; diff --git a/lealone-cluster/src/main/java/org/lealone/cluster/service/StorageService.java b/lealone-cluster/src/main/java/org/lealone/cluster/service/StorageService.java index fda0f700d..db574f486 100644 --- a/lealone-cluster/src/main/java/org/lealone/cluster/service/StorageService.java +++ b/lealone-cluster/src/main/java/org/lealone/cluster/service/StorageService.java @@ -69,6 +69,7 @@ import org.lealone.cluster.utils.Pair; import org.lealone.cluster.utils.Utils; import org.lealone.cluster.utils.WrappedRunnable; +import org.lealone.dbobject.Schema; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -484,8 +485,8 @@ private void setTokens(Collection tokens) { setMode(Mode.NORMAL, false); } - public Collection> getLocalRanges(String keyspaceName) { - return getRangesForEndpoint(keyspaceName, Utils.getBroadcastAddress()); + public Collection> getLocalRanges(Schema schema) { + return getRangesForEndpoint(schema, Utils.getBroadcastAddress()); } public void register(IEndpointLifecycleSubscriber subscriber) { @@ -1135,8 +1136,8 @@ private List stringify(Iterable endpoints) { * @param ep endpoint we are interested in. * @return ranges for the specified endpoint. */ - Collection> getRangesForEndpoint(String keyspaceName, InetAddress ep) { - return Keyspace.open(keyspaceName).getReplicationStrategy().getAddressRanges().get(ep); + Collection> getRangesForEndpoint(Schema schema, InetAddress ep) { + return Keyspace.getReplicationStrategy(schema).getAddressRanges().get(ep); } /** @@ -1163,36 +1164,36 @@ public List> getAllRanges(List sortedTokens) { return ranges; } - public List getNaturalEndpoints(String keyspaceName, ByteBuffer key) { - return getNaturalEndpoints(keyspaceName, getPartitioner().getToken(key)); + public List getNaturalEndpoints(Schema schema, ByteBuffer key) { + return getNaturalEndpoints(schema, getPartitioner().getToken(key)); } /** * This method returns the N endpoints that are responsible for storing the * specified key i.e for replication. * - * @param keyspaceName keyspace name also known as keyspace + * @param schema the schema * @param pos position for which we need to find the endpoint * @return the endpoint responsible for this token */ - public List getNaturalEndpoints(String keyspaceName, RingPosition pos) { - return Keyspace.open(keyspaceName).getReplicationStrategy().getNaturalEndpoints(pos); + public List getNaturalEndpoints(Schema schema, RingPosition pos) { + return Keyspace.getReplicationStrategy(schema).getNaturalEndpoints(pos); } /** * This method attempts to return N endpoints that are responsible for storing the * specified key i.e for replication. * - * @param keyspace keyspace name also known as keyspace + * @param schema the schema * @param key key for which we need to find the endpoint * @return the endpoint responsible for this key */ - public List getLiveNaturalEndpoints(Keyspace keyspace, ByteBuffer key) { - return getLiveNaturalEndpoints(keyspace, getPartitioner().decorateKey(key)); + public List getLiveNaturalEndpoints(Schema schema, ByteBuffer key) { + return getLiveNaturalEndpoints(schema, getPartitioner().decorateKey(key)); } - public List getLiveNaturalEndpoints(Keyspace keyspace, RingPosition pos) { - List endpoints = keyspace.getReplicationStrategy().getNaturalEndpoints(pos); + public List getLiveNaturalEndpoints(Schema schema, RingPosition pos) { + List endpoints = Keyspace.getReplicationStrategy(schema).getNaturalEndpoints(pos); List liveEps = new ArrayList<>(endpoints.size()); for (InetAddress endpoint : endpoints) { diff --git a/lealone-common/src/main/java/org/lealone/command/CommandInterface.java b/lealone-common/src/main/java/org/lealone/command/CommandInterface.java index 2048c2d34..fb24c1ab2 100644 --- a/lealone-common/src/main/java/org/lealone/command/CommandInterface.java +++ b/lealone-common/src/main/java/org/lealone/command/CommandInterface.java @@ -448,6 +448,11 @@ public interface CommandInterface { */ int SHUTDOWN_DEFRAG = 84; + /** + * The type of a ALTER SCHEMA WTIH REPLICATION statement. + */ + int ALTER_SCHEMA_WTIH_REPLICATION = 85; + /** * Get command type. * diff --git a/lealone-sql/src/main/java/org/lealone/command/Parser.java b/lealone-sql/src/main/java/org/lealone/command/Parser.java index 5a1a79fd5..7d4c20b22 100644 --- a/lealone-sql/src/main/java/org/lealone/command/Parser.java +++ b/lealone-sql/src/main/java/org/lealone/command/Parser.java @@ -11,12 +11,15 @@ import java.nio.charset.Charset; import java.text.Collator; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import org.lealone.api.ErrorCode; import org.lealone.api.Trigger; import org.lealone.command.ddl.AlterIndexRename; import org.lealone.command.ddl.AlterSchemaRename; +import org.lealone.command.ddl.AlterSchemaWithReplication; import org.lealone.command.ddl.AlterSequence; import org.lealone.command.ddl.AlterTableAddConstraint; import org.lealone.command.ddl.AlterTableAlterColumn; @@ -4093,9 +4096,31 @@ private CreateSchema parseCreateSchema() { } else { command.setAuthorization(session.getUser().getName()); } + + if (readIf("WITH")) { + read("REPLICATION"); + read("="); + Map replicationProperties = parseMap(); + command.setReplicationProperties(replicationProperties); + checkReplicationProperties(replicationProperties); + } + return command; } + private Map parseMap() { + Map map = new HashMap<>(); + read("("); + while (!readIf(")")) { + String k = readString(); + read(":"); + String v = readString(); + readIf(","); + map.put(k, v); + } + return map; + } + private CreateSequence parseCreateSequence() { boolean ifNotExists = readIfNoExists(); String sequenceName = readIdentifierWithSchema(); @@ -4431,8 +4456,27 @@ private AlterView parseAlterView() { return command; } - private AlterSchemaRename parseAlterSchema() { + private DefineCommand parseAlterSchema() { String schemaName = readIdentifierWithSchema(); + if (readIf("WITH")) { + read("REPLICATION"); + read("="); + AlterSchemaWithReplication command = new AlterSchemaWithReplication(session); + command.setSchema(getSchema(schemaName)); + Map replicationProperties = parseMap(); + command.setReplicationProperties(replicationProperties); + checkReplicationProperties(replicationProperties); + return command; + } + return parseAlterSchemaRename(schemaName); + } + + private void checkReplicationProperties(Map replicationProperties) { + if (replicationProperties != null && !replicationProperties.containsKey("class")) + throw DbException.get(ErrorCode.SYNTAX_ERROR_1, sqlCommand + ", missing replication strategy class"); + } + + private AlterSchemaRename parseAlterSchemaRename(String schemaName) { Schema old = getSchema(); AlterSchemaRename command = new AlterSchemaRename(session); command.setOldSchema(getSchema(schemaName)); diff --git a/lealone-sql/src/main/java/org/lealone/command/ddl/AlterSchemaRename.java b/lealone-sql/src/main/java/org/lealone/command/ddl/AlterSchemaRename.java index 756a245fc..43b952878 100644 --- a/lealone-sql/src/main/java/org/lealone/command/ddl/AlterSchemaRename.java +++ b/lealone-sql/src/main/java/org/lealone/command/ddl/AlterSchemaRename.java @@ -37,6 +37,7 @@ public void setNewName(String name) { newSchemaName = name; } + @Override public int update() { session.commit(true); Database db = session.getDatabase(); @@ -55,6 +56,7 @@ public int update() { return 0; } + @Override public int getType() { return CommandInterface.ALTER_SCHEMA_RENAME; } diff --git a/lealone-sql/src/main/java/org/lealone/command/ddl/AlterSchemaWithReplication.java b/lealone-sql/src/main/java/org/lealone/command/ddl/AlterSchemaWithReplication.java new file mode 100644 index 000000000..c33b2a44e --- /dev/null +++ b/lealone-sql/src/main/java/org/lealone/command/ddl/AlterSchemaWithReplication.java @@ -0,0 +1,59 @@ +/* + * 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.lealone.command.ddl; + +import java.util.Map; + +import org.lealone.command.CommandInterface; +import org.lealone.dbobject.Schema; +import org.lealone.engine.Database; +import org.lealone.engine.Session; + +public class AlterSchemaWithReplication extends DefineCommand { + + private Schema schema; + private Map replicationProperties; + + public AlterSchemaWithReplication(Session session) { + super(session); + } + + public void setSchema(Schema schema) { + this.schema = schema; + } + + @Override + public int update() { + session.commit(true); + Database db = session.getDatabase(); + session.getUser().checkAdmin(); + schema.setReplicationProperties(replicationProperties); + db.update(session, schema); + return 0; + } + + @Override + public int getType() { + return CommandInterface.ALTER_SCHEMA_WTIH_REPLICATION; + } + + public void setReplicationProperties(Map replicationProperties) { + this.replicationProperties = replicationProperties; + } + +} diff --git a/lealone-sql/src/main/java/org/lealone/command/ddl/CreateSchema.java b/lealone-sql/src/main/java/org/lealone/command/ddl/CreateSchema.java index 1c02ff284..858c3012a 100644 --- a/lealone-sql/src/main/java/org/lealone/command/ddl/CreateSchema.java +++ b/lealone-sql/src/main/java/org/lealone/command/ddl/CreateSchema.java @@ -6,6 +6,8 @@ */ package org.lealone.command.ddl; +import java.util.Map; + import org.lealone.api.ErrorCode; import org.lealone.command.CommandInterface; import org.lealone.dbobject.Schema; @@ -24,6 +26,8 @@ public class CreateSchema extends DefineCommand { private String authorization; private boolean ifNotExists; + private Map replicationProperties; + public CreateSchema(Session session) { super(session); } @@ -32,6 +36,7 @@ public void setIfNotExists(boolean ifNotExists) { this.ifNotExists = ifNotExists; } + @Override public int update() { session.getUser().checkAdmin(); session.commit(true); @@ -46,6 +51,7 @@ public int update() { } int id = getObjectId(); Schema schema = new Schema(db, id, schemaName, user, false); + schema.setReplicationProperties(replicationProperties); db.addDatabaseObject(session, schema); return 0; } @@ -58,8 +64,13 @@ public void setAuthorization(String userName) { this.authorization = userName; } + @Override public int getType() { return CommandInterface.CREATE_SCHEMA; } + public void setReplicationProperties(Map replicationProperties) { + this.replicationProperties = replicationProperties; + } + } diff --git a/lealone-sql/src/main/java/org/lealone/dbobject/Schema.java b/lealone-sql/src/main/java/org/lealone/dbobject/Schema.java index 964b2be63..607ba805c 100644 --- a/lealone-sql/src/main/java/org/lealone/dbobject/Schema.java +++ b/lealone-sql/src/main/java/org/lealone/dbobject/Schema.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import org.lealone.api.ErrorCode; import org.lealone.command.ddl.CreateTableData; @@ -23,6 +24,7 @@ import org.lealone.storage.StorageEngine; import org.lealone.storage.StorageEngineManager; import org.lealone.util.New; +import org.lealone.util.StatementBuilder; import org.lealone.util.Utils; /** @@ -42,6 +44,10 @@ public class Schema extends DbObjectBase { private final HashMap constants; private final HashMap functions; + private final String fullName; + private Map replicationProperties; + private ReplicationPropertiesChangeListener replicationPropertiesChangeListener; + /** * The set of returned unique names that are not yet stored. It is used to * avoid returning the same unique name twice when multiple threads @@ -70,6 +76,30 @@ public Schema(Database database, int id, String schemaName, User owner, boolean initDbObjectBase(database, id, schemaName, Trace.SCHEMA); this.owner = owner; this.system = system; + + fullName = database.getShortName() + "." + schemaName; + } + + public String getFullName() { + return fullName; + } + + public Map getReplicationProperties() { + return replicationProperties; + } + + public void setReplicationProperties(Map replicationProperties) { + this.replicationProperties = replicationProperties; + if (replicationPropertiesChangeListener != null) + replicationPropertiesChangeListener.replicationPropertiesChanged(this); + } + + public void setReplicationPropertiesChangeListener(ReplicationPropertiesChangeListener listener) { + replicationPropertiesChangeListener = listener; + } + + public static interface ReplicationPropertiesChangeListener { + void replicationPropertiesChanged(Schema schema); } /** @@ -96,7 +126,18 @@ public String getCreateSQL() { if (system) { return null; } - return "CREATE SCHEMA IF NOT EXISTS " + getSQL() + " AUTHORIZATION " + owner.getSQL(); + + StatementBuilder sql = new StatementBuilder(); + sql.append("CREATE SCHEMA IF NOT EXISTS ").append(getSQL()).append(" AUTHORIZATION ").append(owner.getSQL()); + if (replicationProperties != null && !replicationProperties.isEmpty()) { + sql.append(" WITH REPLICATION = ("); + for (Map.Entry e : replicationProperties.entrySet()) { + sql.appendExceptFirst(","); + sql.append('\'').append(e.getKey()).append("':'").append(e.getValue()).append('\''); + } + sql.append(')'); + } + return sql.toString(); } @Override diff --git a/lealone-test/src/test/java/org/lealone/test/dbobject/SchemaTest.java b/lealone-test/src/test/java/org/lealone/test/dbobject/SchemaTest.java new file mode 100644 index 000000000..c22e8c2f2 --- /dev/null +++ b/lealone-test/src/test/java/org/lealone/test/dbobject/SchemaTest.java @@ -0,0 +1,70 @@ +/* + * 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.lealone.test.dbobject; + +import org.junit.Test; +import org.lealone.dbobject.Schema; + +public class SchemaTest extends DbObjectTestBase { + @Test + public void run() { + String userName = "sa1"; + executeUpdate("CREATE USER IF NOT EXISTS " + userName + " PASSWORD 'abc' ADMIN"); + + int id = db.allocateObjectId(); + String schemaName = "test"; + Schema schema = new Schema(db, id, schemaName, db.getUser(userName), false); + assertEquals(id, schema.getId()); + + db.addDatabaseObject(session, schema); + assertNotNull(db.findSchema(schemaName)); + + db.removeDatabaseObject(session, schema); + assertNull(db.findSchema(schemaName)); + + //测试SQL + //----------------------------------------------- + executeUpdate("CREATE SCHEMA IF NOT EXISTS " + schemaName + " AUTHORIZATION " + userName); + assertNotNull(db.findSchema(schemaName)); + executeUpdate("DROP SCHEMA IF EXISTS " + schemaName); + assertNull(db.findSchema(schemaName)); + + executeUpdate("CREATE SCHEMA IF NOT EXISTS test2 AUTHORIZATION " + userName); + executeUpdate("ALTER SCHEMA test2 RENAME TO " + schemaName); + assertNotNull(db.findSchema(schemaName)); + executeUpdate("DROP SCHEMA IF EXISTS " + schemaName); + + executeUpdate("CREATE SCHEMA IF NOT EXISTS " + schemaName + " AUTHORIZATION " + userName // + + " WITH REPLICATION = ('class': 'SimpleStrategy', 'replication_factor':1)"); + schema = db.findSchema(schemaName); + assertNotNull(schema); + assertNotNull(schema.getReplicationProperties()); + assertTrue(schema.getReplicationProperties().containsKey("class")); + + executeUpdate("ALTER SCHEMA " + schemaName // + + " WITH REPLICATION = ('class': 'SimpleStrategy', 'replication_factor':2)"); + + schema = db.findSchema(schemaName); + assertNotNull(schema); + assertNotNull(schema.getReplicationProperties()); + assertEquals("2", schema.getReplicationProperties().get("replication_factor")); + + executeUpdate("DROP SCHEMA IF EXISTS " + schemaName); + executeUpdate("DROP USER " + userName); + } +} diff --git a/lealone-test/src/test/java/org/lealone/test/sql/dml/InsertTest.java b/lealone-test/src/test/java/org/lealone/test/sql/dml/InsertTest.java index 0c774f796..8e2d2946e 100644 --- a/lealone-test/src/test/java/org/lealone/test/sql/dml/InsertTest.java +++ b/lealone-test/src/test/java/org/lealone/test/sql/dml/InsertTest.java @@ -23,6 +23,13 @@ public class InsertTest extends SqlTestBase { @Test public void run() { + String schemaName = "SCHEMA_FOR_INSERT"; + schemaName = "PUBLIC"; + + executeUpdate("CREATE SCHEMA IF NOT EXISTS " + schemaName // + + " WITH REPLICATION = ('class': 'SimpleStrategy', 'replication_factor':1)"); + //executeUpdate("SET SCHEMA " + schemaName); + createTable("InsertTest"); createTable("InsertTest2"); testInsert();