Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6200b3c
commit cdcac4b
Showing
13 changed files
with
316 additions
and
98 deletions.
There are no files selected for viewing
24 changes: 0 additions & 24 deletions
24
lealone-cluster/src/main/java/org/lealone/cluster/config/ReadRepairDecision.java
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
lealone-cluster/src/main/java/org/lealone/cluster/config/Schema.java
This file was deleted.
Oops, something went wrong.
74 changes: 53 additions & 21 deletions
74
lealone-cluster/src/main/java/org/lealone/cluster/db/Keyspace.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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; | package org.lealone.cluster.db; | ||
|
|
||
import java.util.HashMap; | |||
|
|||
import org.lealone.cluster.config.DatabaseDescriptor; | import org.lealone.cluster.config.DatabaseDescriptor; | ||
import org.lealone.cluster.exceptions.ConfigurationException; | |||
import org.lealone.cluster.locator.AbstractReplicationStrategy; | import org.lealone.cluster.locator.AbstractReplicationStrategy; | ||
|
import org.lealone.cluster.service.StorageService; | ||
public class Keyspace { | import org.lealone.dbobject.Schema; | ||
private static Keyspace INSTANCE = new Keyspace(); | import org.lealone.dbobject.Schema.ReplicationPropertiesChangeListener; | ||
|
|
||
public static Keyspace open(String keyspaceName) { | public class Keyspace implements ReplicationPropertiesChangeListener { | ||
return INSTANCE; | private static final Keyspace INSTANCE = new Keyspace(); | ||
} | private static final HashMap<Schema, AbstractReplicationStrategy> replicationStrategys = new HashMap<>(); | ||
|
private static final AbstractReplicationStrategy defaultReplicationStrategy = DatabaseDescriptor | ||
public static Iterable<Keyspace> all() { | .getDefaultReplicationStrategy(); | ||
return null; |
|
||
} | public static AbstractReplicationStrategy getReplicationStrategy(Schema schema) { | ||
|
if (schema.getReplicationProperties() == null) | ||
private final AbstractReplicationStrategy replicationStrategy; | return defaultReplicationStrategy; | ||
|
AbstractReplicationStrategy replicationStrategy = replicationStrategys.get(schema); | ||
public Keyspace() { | if (replicationStrategy == null) { | ||
//TODO 按表或按数据库配置 | HashMap<String, String> map = new HashMap<>(schema.getReplicationProperties()); | ||
replicationStrategy = DatabaseDescriptor.getDefaultReplicationStrategy(); | 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() { | private Keyspace() { | ||
return replicationStrategy; | |||
} | } | ||
|
|
||
public String getName() { | @Override | ||
return null; | public void replicationPropertiesChanged(Schema schema) { | ||
replicationStrategys.remove(schema); | |||
getReplicationStrategy(schema); | |||
} | } | ||
} | } |
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
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
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
Oops, something went wrong.