Fixed BLUR-253
Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/979f0dea Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/979f0dea Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/979f0dea Branch: refs/heads/0.3.0-lucene-upgrade Commit: 979f0dea4d071a248c2414084a201085ef58d3bf Parents: b580497 Author: Aaron McCurry <[email protected]> Authored: Thu Oct 31 14:11:09 2013 -0400 Committer: Aaron McCurry <[email protected]> Committed: Thu Oct 31 14:11:53 2013 -0400 ---------------------------------------------------------------------- .../indexserver/DistributedIndexServer.java | 8 +-- .../blur/manager/writer/BlurIndexReadOnly.java | 74 ++++++++++++++++++++ .../java/org/apache/blur/BlurConfiguration.java | 25 ++++--- 3 files changed, 93 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/979f0dea/blur-core/src/main/java/org/apache/blur/manager/indexserver/DistributedIndexServer.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/manager/indexserver/DistributedIndexServer.java b/blur-core/src/main/java/org/apache/blur/manager/indexserver/DistributedIndexServer.java index d2f686f..2e548d2 100644 --- a/blur-core/src/main/java/org/apache/blur/manager/indexserver/DistributedIndexServer.java +++ b/blur-core/src/main/java/org/apache/blur/manager/indexserver/DistributedIndexServer.java @@ -46,7 +46,7 @@ import org.apache.blur.manager.clusterstatus.ClusterStatus; import org.apache.blur.manager.clusterstatus.ZookeeperPathConstants; import org.apache.blur.manager.writer.BlurIndex; import org.apache.blur.manager.writer.BlurIndexCloser; -import org.apache.blur.manager.writer.BlurIndexReader; +import org.apache.blur.manager.writer.BlurIndexReadOnly; import org.apache.blur.manager.writer.BlurIndexRefresher; import org.apache.blur.manager.writer.BlurNRTIndex; import org.apache.blur.manager.writer.SharedMergeScheduler; @@ -462,11 +462,11 @@ public class DistributedIndexServer extends AbstractDistributedIndexServer { } BlurIndex index; + + BlurNRTIndex writer = new BlurNRTIndex(shardContext, _mergeScheduler, dir, _gc, _searchExecutor); if (_clusterStatus.isReadOnly(true, _cluster, table)) { - BlurIndexReader reader = new BlurIndexReader(shardContext, dir, _refresher, _indexCloser); - index = reader; + index = new BlurIndexReadOnly(writer); } else { - BlurNRTIndex writer = new BlurNRTIndex(shardContext, _mergeScheduler, dir, _gc, _searchExecutor); index = writer; } _filterCache.opening(table, shard, index); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/979f0dea/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndexReadOnly.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndexReadOnly.java b/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndexReadOnly.java new file mode 100644 index 0000000..1092439 --- /dev/null +++ b/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndexReadOnly.java @@ -0,0 +1,74 @@ +/** + * 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.blur.manager.writer; + +import java.io.IOException; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.apache.blur.server.IndexSearcherClosable; +import org.apache.blur.thrift.generated.Row; + +public class BlurIndexReadOnly extends BlurIndex { + + private final BlurIndex _blurIndex; + + public BlurIndexReadOnly(BlurIndex blurIndex) { + _blurIndex = blurIndex; + } + + public void replaceRow(boolean waitToBeVisible, boolean wal, Row row) throws IOException { + throw new IOException("Read Only"); + } + + public void deleteRow(boolean waitToBeVisible, boolean wal, String rowId) throws IOException { + throw new IOException("Read Only"); + } + + public IndexSearcherClosable getIndexReader() throws IOException { + return _blurIndex.getIndexReader(); + } + + public void close() throws IOException { + _blurIndex.close(); + } + + public void refresh() throws IOException { + _blurIndex.refresh(); + } + + public AtomicBoolean isClosed() { + return _blurIndex.isClosed(); + } + + public void optimize(int numberOfSegmentsPerShard) throws IOException { + _blurIndex.optimize(numberOfSegmentsPerShard); + } + + public void createSnapshot(String name) throws IOException { + _blurIndex.createSnapshot(name); + } + + public void removeSnapshot(String name) throws IOException { + _blurIndex.removeSnapshot(name); + } + + public List<String> getSnapshots() throws IOException { + return _blurIndex.getSnapshots(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/979f0dea/blur-util/src/main/java/org/apache/blur/BlurConfiguration.java ---------------------------------------------------------------------- diff --git a/blur-util/src/main/java/org/apache/blur/BlurConfiguration.java b/blur-util/src/main/java/org/apache/blur/BlurConfiguration.java index 2dca0a3..27af519 100644 --- a/blur-util/src/main/java/org/apache/blur/BlurConfiguration.java +++ b/blur-util/src/main/java/org/apache/blur/BlurConfiguration.java @@ -25,10 +25,10 @@ import java.util.Map.Entry; import java.util.Properties; /** - * The default constructor, which loads site defaults should nearly - * always be used. Instantiating a BlurConfiguration without defaults - * is rarely necessary and should generally be avoided. - * + * The default constructor, which loads site defaults should nearly always be + * used. Instantiating a BlurConfiguration without defaults is rarely necessary + * and should generally be avoided. + * */ public class BlurConfiguration { @@ -41,22 +41,23 @@ public class BlurConfiguration { System.out.println(configuration.get("test3", "def")); } - /** + /** * Create a BlurConfiguration including default properties. + * * @throws IOException */ public BlurConfiguration() throws IOException { this(true); } - + /** * - * @param loadDefaults - - * false to load without default properties set. + * @param loadDefaults + * - false to load without default properties set. * @throws IOException */ public BlurConfiguration(boolean loadDefaults) throws IOException { - if(loadDefaults == true) { + if (loadDefaults == true) { init(); } } @@ -89,7 +90,11 @@ public class BlurConfiguration { } public String get(String name, String defaultValue) { - return _properties.getProperty(name, defaultValue); + String property = _properties.getProperty(name, defaultValue); + if (property == null || property.isEmpty()) { + return defaultValue; + } + return property; } public int getInt(String name, int defaultValue) {
