public class CommitCounterUtility extends Object
The commit counter based files are arranged in a heirarchial directory
structure with 3 digits per directory and 7 directory levels. These levels
are labeled with depths [0..6]
. The root directory is at depth
ZERO (0). Each directory contains up to 1000
children. The
children in the non-leaf directories are subdirectories labeled
0..999
. The leaf directories are at depth SIX (6). Leaf
directories contain files. Each file in a leaf directory is labeled with a
21
digit base name and some purpose specific file extension.
Each such file has data for the specific commit point encoded by the basename
of the file.
Constructor and Description |
---|
CommitCounterUtility() |
Modifier and Type | Method and Description |
---|---|
static File |
findGreatestCommitCounter(File f,
FileFilter fileFilter)
Find and return the
File associated with the greatest commit
counter. |
static String |
getBaseName(String name,
String ext)
Return the basename of the file (strip off the extension).
|
static int |
getBasenameDigits()
The #of digits (21) in the base file name for a commit counter as
formatted by
getCommitCounterStr(long) . |
static File |
getCommitCounterFile(File dir,
long commitCounter,
String ext)
Return the name of the
File associated with the commitCounter. |
static String |
getCommitCounterStr(long commitCounter)
Format the commit counter with leading zeros such that it will be
lexically ordered in the file system.
|
static int |
getDigitsPerDirectory()
The number of base-10 digits per directory level (
).
|
static int |
getFilesPerDirectory()
The number of files per directory ().
|
static int |
getLeafDirectoryDepth()
The depth of a leaf directory ().
|
static int |
getRootDirectoryDepth()
The depth of the root directory ().
|
static long |
parseCommitCounterFile(String name,
String ext)
Parse out the commitCounter from the file name.
|
static void |
recursiveDelete(boolean errorIfDeleteFails,
File f,
FileFilter fileFilter)
Recursively removes any files and subdirectories and then removes the
file (or directory) itself.
|
public static int getBasenameDigits()
getCommitCounterStr(long)
.
Note: 21 := (leafDirDepth+1) * digitsPerDir
public static int getDigitsPerDirectory()
000...999
. Thus there are 1000
children per
directory.public static int getFilesPerDirectory()
public static int getRootDirectoryDepth()
public static int getLeafDirectoryDepth()
public static File getCommitCounterFile(File dir, long commitCounter, String ext)
File
associated with the commitCounter.dir
- The directory spanning all such files.commitCounter
- The commit counter for the current root block on the journal.ext
- The filename extension.public static String getCommitCounterStr(long commitCounter)
commitCounter
- The commit counter.public static long parseCommitCounterFile(String name, String ext) throws NumberFormatException
name
- The file nameext
- The expected file extension.IllegalArgumentException
- if either argument is null
NumberFormatException
- if the file name can not be interpreted as a commit counter.public static String getBaseName(String name, String ext)
name
- The file name.ext
- The extension.public static void recursiveDelete(boolean errorIfDeleteFails, File f, FileFilter fileFilter) throws IOException
#getFileFilter()
will be deleted.
Note: A dedicated version of this method exists here to thrown an
IOException
if we can not delete a file. This is deliberate. It
is thrown to prevent a REBUILD from proceeding unless we can clear out
the old snapshot and HALog files.
errorIfDeleteFails
- When true
and IOException
is thrown if a
file matching the filter or an empty directory matching the
filter can not be removed. When false
, that event
is logged @ WARN instead.f
- A file or directory.fileFilter
- A filter matching the files and directories to be visited and
removed. If directories are matched, then they will be removed
iff they are empty. A depth first visitation is used, so the
files and sub-directories will be cleared before we attempt to
remove the parent directory.IOException
- if any file or non-empty directory can not be deleted (iff
errorIfDeleteFails is true
).public static File findGreatestCommitCounter(File f, FileFilter fileFilter) throws IOException
File
associated with the greatest commit
counter. This uses a reverse order search to locate the most recent file
very efficiently.f
- The root of the directory structure for the snapshot or HALog
files.fileFilter
- Either the SnapshotManager#SNAPSHOT_FILTER
or the
IHALogReader.HALOG_FILTER
.IOException
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.