All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.hadoop.hbase.mob.MobFileName Maven / Gradle / Ivy

There is a newer version: 3.0.0-beta-1
Show newest version
/**
 *
 * 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.hadoop.hbase.mob;

import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.hbase.util.MD5Hash;

/**
 * The mob file name.
 * It consists of a md5 of a start key, a date and an uuid.
 * It looks like md5(start) + date + uuid.
 * 
    *
  1. characters 0-31: md5 hex string of a start key. Since the length of the start key is not * fixed, have to use the md5 instead which has a fix length.
  2. *
  3. characters 32-39: a string of a date with format yyyymmdd. The date is the latest timestamp * of cells in this file
  4. *
  5. the remaining characters: the uuid.
  6. *
* Using md5 hex string of start key as the prefix of file name makes files with the same start * key unique, they're different from the ones with other start keys * The cells come from different regions might be in the same mob file by region split, * this is allowed. * Has the latest timestamp of cells in the file name in order to clean the expired mob files by * TTL easily. If this timestamp is older than the TTL, it's regarded as expired. */ @InterfaceAudience.Private public final class MobFileName { private final String date; private final String startKey; private final String uuid; private final String fileName; private static final int STARTKEY_END_INDEX = 32; private static final int DATE_END_INDEX = 40; private static final int UUID_END_INDEX = 72; /** * @param startKey * The start key. * @param date * The string of the latest timestamp of cells in this file, the format is yyyymmdd. * @param uuid * The uuid */ private MobFileName(byte[] startKey, String date, String uuid) { this.startKey = MD5Hash.getMD5AsHex(startKey, 0, startKey.length); this.uuid = uuid; this.date = date; this.fileName = this.startKey + this.date + this.uuid; } /** * @param startKey * The md5 hex string of the start key. * @param date * The string of the latest timestamp of cells in this file, the format is yyyymmdd. * @param uuid * The uuid */ private MobFileName(String startKey, String date, String uuid) { this.startKey = startKey; this.uuid = uuid; this.date = date; this.fileName = this.startKey + this.date + this.uuid; } /** * Creates an instance of MobFileName * * @param startKey * The md5 hex string of the start key. * @param date * The string of the latest timestamp of cells in this file, the format is yyyymmdd. * @param uuid The uuid. * @return An instance of a MobFileName. */ public static MobFileName create(byte[] startKey, String date, String uuid) { return new MobFileName(startKey, date, uuid); } /** * Creates an instance of MobFileName * * @param startKey * The md5 hex string of the start key. * @param date * The string of the latest timestamp of cells in this file, the format is yyyymmdd. * @param uuid The uuid. * @return An instance of a MobFileName. */ public static MobFileName create(String startKey, String date, String uuid) { return new MobFileName(startKey, date, uuid); } /** * Creates an instance of MobFileName. * @param fileName The string format of a file name. * @return An instance of a MobFileName. */ public static MobFileName create(String fileName) { // The format of a file name is md5HexString(0-31bytes) + date(32-39bytes) + UUID // The date format is yyyyMMdd String startKey = fileName.substring(0, STARTKEY_END_INDEX); String date = fileName.substring(STARTKEY_END_INDEX, DATE_END_INDEX); String uuid = fileName.substring(DATE_END_INDEX, UUID_END_INDEX); return new MobFileName(startKey, date, uuid); } /** * get startKey from MobFileName. * @param fileName file name. * @return startKey */ public static String getStartKeyFromName(final String fileName) { return fileName.substring(0, STARTKEY_END_INDEX); } /** * get date from MobFileName. * @param fileName file name. * @return date */ public static String getDateFromName(final String fileName) { return fileName.substring(STARTKEY_END_INDEX, DATE_END_INDEX); } /** * Gets the hex string of the md5 for a start key. * @return The hex string of the md5 for a start key. */ public String getStartKey() { return startKey; } /** * Gets the date string. Its format is yyyymmdd. * @return The date string. */ public String getDate() { return this.date; } @Override public int hashCode() { return fileName.hashCode(); } @Override public boolean equals(Object anObject) { if (this == anObject) { return true; } if (anObject instanceof MobFileName) { MobFileName another = (MobFileName) anObject; return this.getFileName().equals(another.getFileName()); } return false; } /** * Gets the file name. * @return The file name. */ public String getFileName() { return this.fileName; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy