public class FileProtector extends Object
checkVLSNIndexTruncation(long, com.sleepycat.je.utilint.VLSN), VLSNTracker.tryTruncateFromHead(long, com.sleepycat.je.rep.vlsn.LogItemCache) and VLSNTracker.protectRangeHead(java.lang.String).
We takes pains to avoid synchronizing on FileProtector while truncating the
VLSNIndex head, which is a relatively expensive operation. (The
FileProtector is meant to be used by multiple threads without a lot of
blocking and should perform only a fairly small amount of work while
synchronized.) The following approach is used to truncate the VLSNIndex head
safely:
-- To prevent disk usage limit violations, Cleaner.manageDiskUsage first
tries to delete reserved files without truncating the VLSNIndex. If this
is not sufficient, it then tries to truncate the VLSNIndex head. If the
VLSNIndex head can be truncated, then it tries again to delete reserved
files, since more files should then be unprotected.
-- VLSNTracker synchronization is used to protect the VLSNIndex range. The
vlsnIndexRange ProtectedFileRange is advanced only while synchronized on
the VLSNTracker.
-- VLSNTracker.tryTruncateFromHead (which is synchronized) calls
FileProtector.checkVLSNIndexTruncation to determine where to truncate the
index. Reserved files can be removed from the VLSNIndex range only if
they are not protected by syncup and feeders.
-- The VLSNTracker range is then truncated, and the vlsnIndexRange is
advanced to allow file deletion, all while synchronized on the tracker.
-- When a syncup starts, it adds a ProtectedFileRange with the same
startFile as the vlsnIndexRange. This is done while synchronized on the
VLSNTracker and it prevents the vlsnIndexRange from advancing during the
syncup.
-- When a syncup is successful, on the master the Feeder is initialized and
it adds a ProtectedFileRange to protect the range of the VLSNIndex that
it is reading. This is done BEFORE removing the ProtectedFileRange that
was added at the start of the syncup. This guarantees that the files and
VLSNIndex range used by the feeder will not be truncated/deleted.
Note that the special vlsnIndexRange ProtectedFileRange is excluded from
LogSizeStats to avoid confusion and because this ProtectedFileRange does not
ultimately prevent VLSNIndex head truncation or file deletion.
Barren Files
------------
Files with no replicable entries do not need to be protected by feeders.
See protectFileRange(String, long, boolean, boolean). Barren files
may be created when cleaning is occurring but app writes are not, for
example, when recovering from a cache size configuration error. In this
situation it is important to delete the barren files to reclaim disk space.
Such "barren" files are identified by having null begin/end VLSNs. The
begin/end VLSNs for a file are part of the cleaner metadata that is
collected when the cleaner processes a file. These VLSNs are for replicable
entries only, not migrated entries that happen to contain a VLSN.| Modifier and Type | Class and Description |
|---|---|
static class |
FileProtector.ProtectedActiveFileSet
A ProtectedFileSet created using
protectActiveFiles(java.lang.String). |
static class |
FileProtector.ProtectedFileRange
A ProtectedFileSet created using
protectFileRange(java.lang.String, long). |
static class |
FileProtector.ProtectedFileSet
A ProtectedFileSet is used to prevent a set of files from being deleted.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
BACKUP_NAME |
static String |
DATABASE_COUNT_NAME |
static String |
DISK_ORDERED_CURSOR_NAME |
static String |
FEEDER_NAME |
static String |
NETWORK_RESTORE_NAME |
static String |
SYNCUP_NAME |
static String |
VLSN_INDEX_NAME |
| Modifier and Type | Method and Description |
|---|---|
boolean |
checkVLSNIndexTruncation(Long file)
Determines whether the VLSNIndex ProtectedFileRange should be advanced
to unprotect the given file.
|
Pair<VLSN,Long> |
checkVLSNIndexTruncation(long bytesNeeded,
VLSN preserveVLSN)
Determines whether the VLSNIndex ProtectedFileRange should be advanced
to reclaim bytesNeeded.
|
Pair<Long,NavigableSet<Long>> |
getReservedFileInfo()
Returns a copy of the reserved files along with the total size.
|
boolean |
isActiveOrNewFile(Long file)
Returns whether the given file is active, including the last file
whether or not it has been created on disk yet.
|
boolean |
isReservedFile(Long file)
Returns whether the given file is in the reserved file set.
|
FileProtector.ProtectedActiveFileSet |
protectActiveFiles(String name)
Calls
protectActiveFiles(String, int, boolean) passing 0 for
nReservedFiles and true for protectNewFiles. |
FileProtector.ProtectedActiveFileSet |
protectActiveFiles(String name,
int nReservedFiles,
boolean protectNewFiles)
Returns a ProtectedActiveFileSet that protects all files currently
active at the time of construction.
|
FileProtector.ProtectedFileRange |
protectFileRange(String name,
long rangeStart)
Calls
protectFileRange(String, long, boolean, boolean) passing
false for protectVlsnIndex and true for protectBarrenFiles. |
FileProtector.ProtectedFileRange |
protectFileRange(String name,
long rangeStart,
boolean protectVlsnIndex,
boolean protectBarrenFiles)
Returns a ProtectedFileRange that protects files with numbers GTE a
lower bound.
|
void |
removeFileProtection(FileProtector.ProtectedFileSet pfs)
Removes protection by the given ProtectedFileSet to allow files to be
deleted.
|
void |
setVLSNIndexProtectedFileRange(FileProtector.ProtectedFileRange pfs)
Sets the ProtectedFileRange that protects files in VLSNIndex range
from being deleted.
|
public static final String BACKUP_NAME
public static final String DATABASE_COUNT_NAME
public static final String DISK_ORDERED_CURSOR_NAME
public static final String FEEDER_NAME
public static final String SYNCUP_NAME
public static final String VLSN_INDEX_NAME
public static final String NETWORK_RESTORE_NAME
public void removeFileProtection(FileProtector.ProtectedFileSet pfs)
public FileProtector.ProtectedFileRange protectFileRange(String name, long rangeStart)
protectFileRange(String, long, boolean, boolean) passing
false for protectVlsnIndex and true for protectBarrenFiles.public FileProtector.ProtectedFileRange protectFileRange(String name, long rangeStart, boolean protectVlsnIndex, boolean protectBarrenFiles)
rangeStart - is the first file to be protected in the range.protectVlsnIndex - is whether to prevent the VLSNIndex head from
advancing.protectBarrenFiles - is whether barren files (having no replicable
entries) are protected.public FileProtector.ProtectedActiveFileSet protectActiveFiles(String name)
protectActiveFiles(String, int, boolean) passing 0 for
nReservedFiles and true for protectNewFiles.public FileProtector.ProtectedActiveFileSet protectActiveFiles(String name, int nReservedFiles, boolean protectNewFiles)
nReservedFiles - if greater than zero, this number of the newest
(highest numbered) reserved files are also protected.protectNewFiles - if true, the last file and any new files created
later are also protected.public Pair<Long,NavigableSet<Long>> getReservedFileInfo()
public boolean isActiveOrNewFile(Long file)
public boolean isReservedFile(Long file)
public void setVLSNIndexProtectedFileRange(FileProtector.ProtectedFileRange pfs)
VLSNTracker.protectRangeHead(java.lang.String).public Pair<VLSN,Long> checkVLSNIndexTruncation(long bytesNeeded, VLSN preserveVLSN)
bytesNeeded - the number of bytes we need to free.preserveVLSN - is the boundary above which the VLSN range may not
advance. The deleteEnd returned will be less than preserveVLSN.public boolean checkVLSNIndexTruncation(Long file)
file - that should be unprotected.Copyright © 2024. All rights reserved.