Class WarmerListStore
java.lang.Object
org.frontcache.warmer.WarmerListStore
The URI lists under
FRONTCACHE_HOME/warmer/, and the only place a list name becomes a
File.
Names are caller-supplied, so they are constrained
ConfigFile is an enum because the set of config files is closed. The set of lists is not -
an operator names them - so the defence here is a check, written to be hard to get slightly wrong:
- the name must match
NAME. That character class cannot express a separator, a..segment is impossible without a/, and a leading dot is excluded - which is also what keeps.state/and this class's own temp files out of every listing; - the resolved file's canonical parent must be the canonical
warmer/directory, which covers a symlink placed in the directory by hand.
What a list's content is, byte for byte
UTF-8, LF line endings, no BOM. A write normalizes CRLF (and a lone CR) to LF and strips a BOM, and adds no trailing newline - saving a list unchanged must not change it.hash(String) is the SHA-256
of the content after that same normalization, so a file copied in by hand with CRLF endings hashes
the same as the text the console shows for it.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThrown when a write is refused - too large, or the list changed since it was read. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncachedHash(String name) hash(String), remembered per (mtime, size).warmer/.state/run.json- a fixed name, never caller-supplied.createFailedList(String name) A new file for a run's failed entries.booleanRemoves one list.booleanstatic StringfailedListName(String listName, String stamp) The name the failed entries of a run overlistNamego to.static WarmerListStoreforNode()The store for this node:FRONTCACHE_HOME/warmer, created if absent.Lines containingneedle(case-insensitive), with their line numbers - a streamed scan, so a 50k-line list can be searched without being loaded.SHA-256 of the list's normalized content, streamed.static StringSHA-256 (lowercase hex) of normalized text - thebaseHashthe console sends back.list(long editMaxBytes) Every list, newest first.static StringnameProblem(String name) static StringCRLF and a lone CR to LF, a leading BOM removed.The raw bytes, for a download.openReader(String name) A UTF-8 reader over the list.Whatget-warmer-listshows: the whole normalized content and its hash when the list is small enough to edit, otherwise the first and lastpreviewLineslines.write(String name, InputStream body, long maxBytes, String baseHash, long editMaxBytes) Creates or replaces one list from a stream, never holding it whole.
-
Field Details
-
NAME
See the class comment. 1 + 99 characters, then.txt.
-
-
Constructor Details
-
WarmerListStore
-
-
Method Details
-
forNode
The store for this node:FRONTCACHE_HOME/warmer, created if absent. The directory is the onedump-keyshas always written to. -
getDirectory
-
nameProblem
-
resolve
- Returns:
- the list's file, which need not exist
- Throws:
IllegalArgumentException- when the name is not a list name or resolves outside warmer/
-
exists
-
failedListName
-
list
Every list, newest first. Entry counts are cached per (name, mtime, size).- Throws:
IOException
-
info
- Throws:
IOException
-
openReader
A UTF-8 reader over the list.readLine()already treats CRLF and a lone CR as LF.- Throws:
IOException
-
openRaw
The raw bytes, for a download.- Throws:
IOException
-
read
Whatget-warmer-listshows: the whole normalized content and its hash when the list is small enough to edit, otherwise the first and lastpreviewLineslines.- Returns:
- null when the list does not exist
- Throws:
IOException
-
grep
Lines containingneedle(case-insensitive), with their line numbers - a streamed scan, so a 50k-line list can be searched without being loaded.- Throws:
IOException
-
normalize
-
hashOf
-
hash
SHA-256 of the list's normalized content, streamed. Null when the list does not exist.- Throws:
IOException
-
cachedHash
hash(String), remembered per (mtime, size). For the callers that ask repeatedly about the same file - the status poll's "is the checkpoint still resumable?" - and must not re-read 64 MB to find out.- Throws:
IOException
-
write
public WarmerListInfo write(String name, InputStream body, long maxBytes, String baseHash, long editMaxBytes) throws IOException, WarmerListStore.RefusedException Creates or replaces one list from a stream, never holding it whole. The body goes into a temp file in warmer/, normalized as it is copied, and is moved into place atomically once it is complete - theConfigFileStoremechanics, including the reason for the same directory:ATOMIC_MOVEacross filesystems throws. PastmaxBytesthe copy stops, the temp file is deleted, and nothing is replaced.- Parameters:
baseHash- the hash the caller last read, or null to skip the concurrency check- Returns:
- the list as written
- Throws:
IOExceptionWarmerListStore.RefusedException
-
delete
Removes one list. @return false when there was nothing to remove- Throws:
IOException
-
createFailedList
A new file for a run's failed entries.CREATE_NEW: a name that already exists is never appended to or overwritten.- Throws:
IOException
-
checkpointFile
warmer/.state/run.json- a fixed name, never caller-supplied.
-