Exemple #1
0
        internal override void Visit(UploadVersionRequest req)
        {
            VersionEntry ve = this.GetVersionEntryByKey(req.TableId, req.RecordKey, req.VersionKey, req.LocalVerEntry);

            if (ve == null)
            {
                this.CQLExecute(string.Format(PartitionedCassandraVersionTable.CQL_UPLOAD_VERSION_ENTRY,
                                              req.TableId,
                                              req.RecordKey.ToString(),
                                              req.VersionEntry.VersionKey,
                                              req.VersionEntry.BeginTimestamp,
                                              req.VersionEntry.EndTimestamp,
                                              BytesSerializer.ToHexString(BytesSerializer.Serialize(req.VersionEntry.Record)),
                                              req.VersionEntry.TxId,
                                              req.VersionEntry.MaxCommitTs));
                req.RemoteVerEntry = req.VersionEntry;
                req.Result         = true;
            }
            else        // write-write conflict
            {
                req.RemoteVerEntry = req.VersionEntry;
                req.Result         = false;
            }

            req.Finished = true;
        }
Exemple #2
0
 internal override void Visit(ReplaceWholeVersionRequest req)
 {
     this.CQLExecute(string.Format(PartitionedCassandraVersionTable.CQL_REPLACE_WHOLE_VERSION,
                                   req.TableId, req.VersionEntry.BeginTimestamp, req.VersionEntry.EndTimestamp,
                                   BytesSerializer.ToHexString(BytesSerializer.Serialize(req.VersionEntry.Record)),
                                   req.VersionEntry.TxId, req.VersionEntry.MaxCommitTs,
                                   req.RecordKey.ToString(), req.VersionEntry.VersionKey));
     req.Result   = 1L;
     req.Finished = true;
 }
Exemple #3
0
        /// <summary>
        /// Serialize essential properties in version entry to bytes array
        /// </summary>
        ///
        /// The format of bytes stream is like:
        /// ------- 8 bytes------ ------- 8 bytes---- --- 8 bytes------ 8 bytes----- --X bytes----
        /// [beginTimestamp bytes][endTimestamp bytes][txId bytes][maxCommitTs bytes][record bytes]
        ///
        /// <returns>a byte array</returns>
        public static byte[] Serialize(VersionEntry versionEntry)
        {
            List <byte> byteList = new List <byte>();

            byteList.AddRange(BitConverter.GetBytes(versionEntry.BeginTimestamp));
            byteList.AddRange(BitConverter.GetBytes(versionEntry.EndTimestamp));
            byteList.AddRange(BitConverter.GetBytes(versionEntry.TxId));
            byteList.AddRange(BitConverter.GetBytes(versionEntry.MaxCommitTs));
            byteList.AddRange(BytesSerializer.Serialize(versionEntry.Record));

            return(byteList.ToArray());
        }
Exemple #4
0
        internal override void Visit(InitiGetVersionListRequest req)
        {
            VersionEntry emptyEntry = VersionEntry.InitEmptyVersionEntry();

            this.CQLExecute(string.Format(PartitionedCassandraVersionTable.CQL_UPLOAD_VERSION_ENTRY,
                                          req.TableId,
                                          req.RecordKey.ToString(),
                                          emptyEntry.VersionKey,
                                          emptyEntry.BeginTimestamp,
                                          emptyEntry.EndTimestamp,
                                          BytesSerializer.ToHexString(BytesSerializer.Serialize(emptyEntry.Record)),
                                          emptyEntry.TxId,
                                          emptyEntry.MaxCommitTs));
            req.Result   = true;
            req.Finished = true;
        }
Exemple #5
0
        internal bool InsertCommittedVersion(string tableId, object recordKey, object payload, long txId, long commitTs)
        {
            if (!this.tableSet.Contains(tableId))
            {
                lock (this.tableLock)
                {
                    if (!this.tableSet.Contains(tableId))
                    {
                        try
                        {
                            this.session.Execute($@"
									CREATE TABLE {CassandraLogStore.KEYSPACE + "." + tableId} (
                                    recordKey blob,
                                    beginTs bigint,
                                    txId bigint,
                                    payload blob,
                                    PRIMARY KEY (recordKey, beginTs)
                                );");
                        }
                        catch (DriverException e)
                        {
                            return(false);
                        }

                        this.tableSet.Add(tableId);
                    }
                }
            }

            try
            {
                PreparedStatement ps        = this.session.Prepare($@"
                        INSERT INTO {CassandraLogStore.KEYSPACE + "." + tableId} (recordKey, beginTs, txId, payload) VALUES (?, ?, ?, ?)");
                Statement         statement = ps.Bind(BytesSerializer.Serialize(recordKey),
                                                      commitTs, txId, BytesSerializer.Serialize(payload));
                session.Execute(statement);
            }
            catch (DriverException e)
            {
                return(false);
            }

            return(true);
        }
        internal override void Visit(UploadVersionRequest req)
        {
            bool applied = this.CQLExecuteWithIfApplied(string.Format(CassandraVersionTable.CQL_UPLOAD_VERSION_ENTRY,
                                                                      req.TableId,
                                                                      req.RecordKey.ToString(),
                                                                      req.VersionEntry.VersionKey,
                                                                      req.VersionEntry.BeginTimestamp,
                                                                      req.VersionEntry.EndTimestamp,
                                                                      BytesSerializer.ToHexString(BytesSerializer.Serialize(req.VersionEntry.Record)),
                                                                      req.VersionEntry.TxId,
                                                                      req.VersionEntry.MaxCommitTs));

            req.Result   = applied ? 1L : 0L;
            req.Finished = true;
        }