Example #1
0
        /// <summary>
        /// HashDB manager
        /// MUST BE A POWER OF 2
        /// </summary>
        /// <param name="minBlockSize">POWER of 2</param>
        /// <param name="DB">Primary DB</param>
        /// <param name="relocFolder">Relocation data</param>
        /// <param name="Size">POWER OF 2!</param>
        public HashDB(int minBlockSize, string DB, string relocFolder, long Size = 0)
        {
            HashDBFile   = DB;
            HashDBBitMap = DB + ".bin";
            if (Size != 0)
            {
                DBSize = (long)FractHashTree.RoundUpPow2(Size);
            }

            if (!File.Exists(HashDBFile))
            {
                if (!FractHashTree.IsPow2(DBSize))
                {
                    throw new InternalBufferOverflowException($"DB SIZE not a power of 2!");
                }

                using (var fileStream = new FileStream(HashDBFile, FileMode.Create, FileAccess.Write, FileShare.None))
                    fileStream.SetLength(DBSize + (DB_READ_SIZE));
            }
            else
            {
                DBSize = (long)FractHashTree.RoundDownPow2(new FileInfo(HashDBFile).Length);
            }

            // Divide by HASH size
            DBEntries     = (ulong)DBSize >> HASH_SHIFT;
            DBEntriesMask = (ulong)DBEntries - 1;

            MinBlockSize = minBlockSize;

            ReRe = new ReReDB(relocFolder);

            HDBBitMap = new UnsafeHelp(HashDBBitMap, (long)DBEntries);
        }
Example #2
0
        public MetaDB(string WorkingDir, int minHashSize = 256, long DBSize = 0, int loadBufferCount = 50000000, string NewInfoString = null)
        {
            RootFolder = WorkingDir;
            if (!Directory.Exists(RootFolder))
            {
                Directory.CreateDirectory(RootFolder);
            }

            MDBName         = Path.Combine(RootFolder, mdbName);
            HDBName         = Path.Combine(RootFolder, hdbName);
            BDBName         = Path.Combine(RootFolder, bdbName);
            RelocName       = Path.Combine(RootFolder, relocFolder);
            LoadBufferCount = loadBufferCount;

            if (File.Exists(MDBName))
            {
                xDoc = XDocument.Load(MDBName);
            }
            else
            {
                xDoc = new XDocument(new XDeclaration("1.0", Encoding.Default.WebName, "yes"), new XElement(ElementNames.xRoot));
            }

            mData = xDoc.Root;

            var currID = ((Int32?)mData.Attribute(AttributeNames.xNextHashID) ?? 0);

            if (currID == 0)
            {
                mData.SetAttributeValue(AttributeNames.xNextHashID, 1);
                currHID = 1;
            }
            else
            {
                currHID = currID;
            }

            if (mData.Element(ElementNames.xRecords) != null)
            {
                mRecords = mData.Element(ElementNames.xRecords);
            }
            else
            {
                mRecords = new XElement(ElementNames.xRecords);
                mData.Add(mRecords);
            }

            if (mData.Element(ElementNames.xMetaInfoStrings) != null)
            {
                infoStrings = mData.Element(ElementNames.xMetaInfoStrings);
            }
            else
            {
                infoStrings = new XElement(ElementNames.xMetaInfoStrings);
                mData.Add(infoStrings);
            }
            infoString  = NewInfoString;
            MinHashSize = minHashSize;

            ReRe = new ReReDB(RelocName);

            HDB      = new HashDB(MinHashSize, HDBName, RelocName, DBSize);
            HDB.ReRe = ReRe;

            Loader = new FileLoader(this, LoadBufferCount, infoString);

            cLoader            = new CloudLoader(Loader, MinHashSize, RelocName);
            cLoader.InfoString = infoString;
            ReRe.AzureCnx      = cLoader;
        }