001    /*
002    Copyright (c) 1996-2012, Damon Hart-Davis
003    All rights reserved.
004    
005    Redistribution and use in source and binary forms, with or without
006    modification, are permitted provided that the following conditions are
007    met:
008    
009      * Redistributions of source code must retain the above copyright
010        notice, this list of conditions and the following disclaimer.
011    
012      * Redistributions in binary form must reproduce the above copyright
013        notice, this list of conditions and the following disclaimer in the
014        documentation and/or other materials provided with the
015        distribution.
016    
017    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
018    IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
019    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
020    PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
021    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
022    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
023    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
024    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
025    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
026    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
027    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028    */
029    
030    package org.hd.d.pg2k.svrCore.FEC;
031    
032    /**This holds compile-time constants for forward-error-correction (FEC) of exhibit data.
033     */
034    public final class FECConsts
035        {
036        /**Prevent construction of an instance. */
037        private FECConsts() { }
038    
039    
040        /**Disc block size; postitive power of two larger than a disc sector.
041         * We assume that an especially common failure mode
042         * is for an entire sector to become unrecoverably unreadable,
043         * and thus our repair algorithm should work when a block
044         * at least this large (and on this alignment) fails.
045         * <p>
046         * Current common (2006) sector sizes are 512 bytes for magnetic media
047         * and 1024 bytes for optical media,
048         * with 4096 bytes being proposed as a new standard circa 2006.
049         * <p>
050         * We use the largest of these as our fundamental FEC block size.
051         */
052        public static final int BASIC_FEC_BLOCK_BYTES = (1<<12);
053    
054        /**FEC protection unit/block size; a positive power of two much larger than BASIC_FEC_BLOCK_BYTES.
055         * Each block of this size of a raw exhibit file (and on this alignment)
056         * is treated independently by the FEC algorithm.
057         * <p>
058         * Any one exhibit will have a single fixable-unit block size,
059         * though some exhibits may transiently have a different-to-this size
060         * after a change in this value until the FEC data can be recomputed.
061         * <p>
062         * Its is useful be able to manipulate (multiple variants of)
063         * a whole such block in memory without straining the JVM/OS,
064         * and so a value from hundreds of kB to tens of MB is probably reasonable.
065         */
066        public static final int FIXABLE_UNIT_FEC_BLOCK_SIZE = (1<<20);
067    
068        /**The "fixable unit" block-checksum cryptographic checksum algorithm name.
069         * We want a modern, reliable, reasonably-fast, JVM-supported algorithm,
070         * different to (and stronger/better than) the MD5 algorithm
071         * used to checksum entire exhibit files.
072         * <p>
073         * Ideally it should also be different to any underlying filesystem checksum
074         * (such as hard-disc CRCs/ECCs and the ZFS SHA-256 block-check),
075         * so as to maximise the chance of this FEC algorithm caching something
076         * that the others miss.
077         */
078        public static final String FIXABLE_UNIT_FEC_CHECKSUM_ALG = "SHA-512";
079    
080        /**Minimum number of "basic FEC block" failures per "fixable unit block" to be able to recover from; strictly positive.
081         * For RS-style FEC the extra file space overhead is directly proportional to this.
082         * <p>
083         * Since we are expecting the underlying filesystem to have a very low
084         * undetected/unrecoverable error rate then this can reasonably be as low as one.
085         * <p>
086         * We may be prepared to provide extra recovery/protection
087         * for popular and/or heavily-used and/or designated exhibits.
088         */
089        public static final int MIN_BASIC_BLOCKS_REPAIRABLE = 1;
090        }