Example #1
0
        public void AddNewAssurance(byte[] indexId, uint rep, byte[] plainHash, uint compressedSize, Action _additionalActionForTransaction = null)
        {
            var segment = new SQLMap.Segment
            {
                IsNew            = true,
                IndexID          = indexId,
                Replication      = rep,
                PlainHash        = plainHash,
                CompressedLength = compressedSize,
            };

            lock (con)
            {
                if (_additionalActionForTransaction == null)
                {
                    con.Insert(segment);
                }
                else
                {
                    con.RunInTransaction(() =>
                    {
                        con.Insert(segment);
                        _additionalActionForTransaction();
                    });
                }
            }
        }
Example #2
0
        public void AddNewAssuranceAndTmpData(byte[] indexId, uint rep, byte[] plainHash, uint compressedSize, byte[] tmpBytesCompressed, Action _additionalActionForTransaction = null)
        {
            lock (con)             // MAYBE: something better than lock? we get a savePoint error otherwise atm.
            {
                con.RunInTransaction(() =>
                {
                    var segment = new SQLMap.Segment
                    {
                        IsNew            = true,
                        IndexID          = indexId,
                        Replication      = rep,
                        PlainHash        = plainHash,
                        CompressedLength = compressedSize,
                    };
                    con.Insert(segment);

                    // get next collectionId and elementId
                    var pr = con.Query <SQLMap.ParityRelation>(@"
						select collectionId, elementId + 1 elementId from (
							select collectionId, elementId from parityrelation where state = ?
							order by collectionId desc, elementId desc
							limit 1
						) x
						union
						select coalesce(max(collectionId) + 1, 1) collectionId, 1 elementId from parityrelation
						limit 1
					"                    , SQLMap.ParityRelationState.FillingUp).First();

#if USE_ALTERNATIE_RAW_CACHE
                    var dir = Path.Combine(cachePath, "tmpDataCompressed", pr.CollectionID.ToString());
                    Directory.CreateDirectory(dir);
                    safeSave(Path.Combine(dir, pr.ElementID.ToString()), tmpBytesCompressed);
#endif

                    var parityRelation = new SQLMap.ParityRelation
                    {
                        IsNew           = true,
                        State           = SQLMap.ParityRelationState.FillingUp,
                        CollectionID    = pr.CollectionID,
                        ElementID       = pr.ElementID,
                        PlainHash       = plainHash,
                        IsParityElement = false,
                    };
#if !USE_ALTERNATIE_RAW_CACHE
                    parityRelation.TmpDataCompressed = tmpBytesCompressed;
#endif
                    con.Insert(parityRelation);


                    // set state to processing if needed
                    con.Query <SQLMap.ParityRelation>(@"
						update parityrelation
						set state = ?
						where state = ? and (
							select count(*) from parityrelation pr2 where pr2.collectionId = parityrelation.collectionId and (not pr2.isParityElement)
						) >= ?
					"                    , SQLMap.ParityRelationState.Processing, SQLMap.ParityRelationState.FillingUp, Constants.DataBeforeParity);

                    if (_additionalActionForTransaction != null)
                    {
                        _additionalActionForTransaction();
                    }
                });
            }
        }