org.apache.zookeeper.server.persistence
类 Util

java.lang.Object
  继承者 org.apache.zookeeper.server.persistence.Util

public class Util
extends java.lang.Object

A collection of utility methods for dealing with file name parsing, low level I/O file operations and marshalling/unmarshalling.


构造方法摘要
Util()
           
 
方法摘要
static java.lang.String getFormatConversionPolicy(java.util.Properties props)
          Extracts the value of the dbFormatConversion attribute.
static java.io.File getLogDir(java.util.Properties props)
          Extracts transaction log directory property value from the container.
static java.io.File getSnapDir(java.util.Properties props)
          Extracts snapshot directory property value from the container.
static long getZxidFromName(java.lang.String name, java.lang.String prefix)
          Extracts zxid from the file name.
static boolean isValidSnapshot(java.io.File f)
          Verifies that the file is a valid snapshot.
static java.net.URI makeFileLoggerURL(java.io.File dataDir, java.io.File dataLogDir)
          Given two directory files the method returns a well-formed logfile provider URI.
static java.net.URI makeFileLoggerURL(java.io.File dataDir, java.io.File dataLogDir, java.lang.String convPolicy)
           
static java.lang.String makeLogName(long zxid)
          Creates a valid transaction log file name.
static java.lang.String makeSnapshotName(long zxid)
          Creates a snapshot file name.
static java.lang.String makeURIString(java.lang.String dataDir, java.lang.String dataLogDir, java.lang.String convPolicy)
           
static byte[] marshallTxnEntry(org.apache.zookeeper.txn.TxnHeader hdr, Record txn)
          Serializes transaction header and transaction data into a byte buffer.
static long padLogFile(java.io.FileOutputStream f, long currentSize, long preAllocSize)
          Grows the file to the specified number of bytes.
static byte[] readTxnBytes(InputArchive ia)
          Reads a transaction entry from the input archive.
static java.util.List<java.io.File> sortDataDir(java.io.File[] files, java.lang.String prefix, boolean ascending)
          Sort the list of files.
static void writeTxnBytes(OutputArchive oa, byte[] bytes)
          Write the serialized transaction record to the output archive.
 
从类 java.lang.Object 继承的方法
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

Util

public Util()
方法详细信息

makeURIString

public static java.lang.String makeURIString(java.lang.String dataDir,
                                             java.lang.String dataLogDir,
                                             java.lang.String convPolicy)

makeFileLoggerURL

public static java.net.URI makeFileLoggerURL(java.io.File dataDir,
                                             java.io.File dataLogDir)
Given two directory files the method returns a well-formed logfile provider URI. This method is for backward compatibility with the existing code that only supports logfile persistence and expects these two parameters passed either on the command-line or in the configuration file.

参数:
dataDir - snapshot directory
dataLogDir - transaction log directory
返回:
logfile provider URI

makeFileLoggerURL

public static java.net.URI makeFileLoggerURL(java.io.File dataDir,
                                             java.io.File dataLogDir,
                                             java.lang.String convPolicy)

makeLogName

public static java.lang.String makeLogName(long zxid)
Creates a valid transaction log file name.

参数:
zxid - used as a file name suffix (extention)
返回:
file name

makeSnapshotName

public static java.lang.String makeSnapshotName(long zxid)
Creates a snapshot file name.

参数:
zxid - used as a suffix
返回:
file name

getSnapDir

public static java.io.File getSnapDir(java.util.Properties props)
Extracts snapshot directory property value from the container.

参数:
props - properties container
返回:
file representing the snapshot directory

getLogDir

public static java.io.File getLogDir(java.util.Properties props)
Extracts transaction log directory property value from the container.

参数:
props - properties container
返回:
file representing the txn log directory

getFormatConversionPolicy

public static java.lang.String getFormatConversionPolicy(java.util.Properties props)
Extracts the value of the dbFormatConversion attribute.

参数:
props - properties container
返回:
value of the dbFormatConversion attribute

getZxidFromName

public static long getZxidFromName(java.lang.String name,
                                   java.lang.String prefix)
Extracts zxid from the file name. The file name should have been created using one of the makeLogName or makeSnapshotName.

参数:
name - the file name to parse
prefix - the file name prefix (snapshot or log)
返回:
zxid

isValidSnapshot

public static boolean isValidSnapshot(java.io.File f)
                               throws java.io.IOException
Verifies that the file is a valid snapshot. Snapshot may be invalid if it's incomplete as in a situation when the server dies while in the process of storing a snapshot. Any file that is not a snapshot is also an invalid snapshot.

参数:
f - file to verify
返回:
true if the snapshot is valid
抛出:
java.io.IOException

padLogFile

public static long padLogFile(java.io.FileOutputStream f,
                              long currentSize,
                              long preAllocSize)
                       throws java.io.IOException
Grows the file to the specified number of bytes. This only happenes if the current file position is sufficiently close (less than 4K) to end of file.

参数:
f - output stream to pad
currentSize - application keeps track of the cuurent file size
preAllocSize - how many bytes to pad
返回:
the new file size. It can be the same as currentSize if no padding was done.
抛出:
java.io.IOException

readTxnBytes

public static byte[] readTxnBytes(InputArchive ia)
                           throws java.io.IOException
Reads a transaction entry from the input archive.

参数:
ia - archive to read from
返回:
null if the entry is corrupted or EOF has been reached; a buffer (possible empty) containing serialized transaction record.
抛出:
java.io.IOException

marshallTxnEntry

public static byte[] marshallTxnEntry(org.apache.zookeeper.txn.TxnHeader hdr,
                                      Record txn)
                               throws java.io.IOException
Serializes transaction header and transaction data into a byte buffer.

参数:
hdr - transaction header
txn - transaction data
返回:
serialized transaction record
抛出:
java.io.IOException

writeTxnBytes

public static void writeTxnBytes(OutputArchive oa,
                                 byte[] bytes)
                          throws java.io.IOException
Write the serialized transaction record to the output archive.

参数:
oa - output archive
bytes - serialized trasnaction record
抛出:
java.io.IOException

sortDataDir

public static java.util.List<java.io.File> sortDataDir(java.io.File[] files,
                                                       java.lang.String prefix,
                                                       boolean ascending)
Sort the list of files. Recency as determined by the version component of the file name.

参数:
files - array of files
prefix - files not matching this prefix are assumed to have a version = -1)
ascending - true sorted in ascending order, false results in descending order
返回:
sorted input files