
com.senseidb.indexing.hadoop.keyvalueformat.Shard Maven / Gradle / Ivy
/**
* 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 com.senseidb.indexing.hadoop.keyvalueformat;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableComparable;
import com.senseidb.indexing.hadoop.util.SenseiJobConfig;
/**
* This class represents the metadata of a shard. Version is the version number
* of the entire index. Directory is the directory where this shard resides in.
* Generation is the Lucene index's generation. Version and generation are
* reserved for future use.
*
* Note: Currently the version number of the entire index is not used and
* defaults to -1.
*/
public class Shard implements WritableComparable {
// This method is copied from Path.
public static String normalizePath(String path) {
// remove double slashes & backslashes
path = path.replace("//", "/");
path = path.replace("\\", "/");
// trim trailing slash from non-root path (ignoring windows drive)
if (path.length() > 1 && path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
return path;
}
public static void setIndexShards(Configuration conf,
Shard[] shards) {
StringBuilder shardsString = new StringBuilder(shards[0].toString());
for (int i = 1; i < shards.length; i++) {
shardsString.append(",");
shardsString.append(shards[i].toString());
}
conf.set(SenseiJobConfig.INDEX_SHARDS, shardsString.toString());
}
public static Shard[] getIndexShards(Configuration conf) {
String shards = conf.get(SenseiJobConfig.INDEX_SHARDS);
if (shards != null) {
ArrayList
© 2015 - 2025 Weber Informatics LLC | Privacy Policy