Ejemplo n.º 1
0
        public ExecuteRequest(int protocolVersion, byte[] id, RowSetMetadata metadata, bool tracingEnabled, QueryProtocolOptions queryOptions)
        {
            ProtocolVersion = protocolVersion;
            if (metadata != null && queryOptions.Values.Length != metadata.Columns.Length)
            {
                throw new ArgumentException("Number of values does not match with number of prepared statement markers(?).", "values");
            }
            _id           = id;
            _metadata     = metadata;
            _queryOptions = queryOptions;
            if (tracingEnabled)
            {
                _flags = 0x02;
            }

            if (Consistency.IsSerialConsistencyLevel())
            {
                throw new RequestInvalidException("Serial consistency specified as a non-serial one.");
            }
            if (queryOptions.SerialConsistency != ConsistencyLevel.Any && queryOptions.SerialConsistency.IsSerialConsistencyLevel() == false)
            {
                throw new RequestInvalidException("Non-serial consistency specified as a serial one.");
            }
            if (queryOptions.Timestamp != null && protocolVersion < 3)
            {
                throw new NotSupportedException("Timestamp for query is supported in Cassandra 2.1 or above.");
            }
        }
Ejemplo n.º 2
0
 /// <inheritdoc/>
 public override int GetHashCode()
 {
     unchecked
     {
         return((Key.GetHashCode() * 397) ^ (Consistency?.GetHashCode() ?? 0));
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the best (lowest rank) server that can provide the desired consistency for the given object.
        /// </summary>
        /// <param name="objectName">Name of the object being read</param>
        /// <param name="consistency">Desired consistency</param>
        /// <param name="bound">Time bound for bounded staleness (in seconds)</param>
        /// <returns>The selected server.</returns>
        public ServerState SelectServerForConsistency(string objectName, Consistency consistency, int bound)
        {
            HashSet <ServerState> set;

            set = SelectServersForConsistency(objectName, consistency, bound);
            return(SelectBestServer(set));
        }
Ejemplo n.º 4
0
 public QueryRequest(int protocolVersion, string cqlQuery, bool tracingEnabled, QueryProtocolOptions queryOptions)
 {
     //TODO: Replace constructor parameters with IStatement
     ProtocolVersion = protocolVersion;
     _cqlQuery       = cqlQuery;
     _queryOptions   = queryOptions;
     if (tracingEnabled)
     {
         _headerFlags = FrameHeader.HeaderFlag.Tracing;
     }
     if (queryOptions == null)
     {
         throw new ArgumentNullException("queryOptions");
     }
     if (Consistency.IsSerialConsistencyLevel())
     {
         throw new RequestInvalidException("Serial consistency specified as a non-serial one.");
     }
     if (queryOptions.SerialConsistency != ConsistencyLevel.Any && queryOptions.SerialConsistency.IsSerialConsistencyLevel() == false)
     {
         throw new RequestInvalidException("Non-serial consistency specified as a serial one.");
     }
     if (protocolVersion < 3)
     {
         //Features supported in protocol v3 and above
         if (queryOptions.Timestamp != null)
         {
             throw new NotSupportedException("Timestamp for query is supported in Cassandra 2.1 and above.");
         }
         if (queryOptions.ValueNames != null && queryOptions.ValueNames.Count > 0)
         {
             throw new NotSupportedException("Query parameter names feature is supported in Cassandra 2.1 and above.");
         }
     }
 }
Ejemplo n.º 5
0
 public static void init()
 {
     consistency = PIMConfigs.Consistency_Model;
     if (consistency == Consistency.SpinLock)
     {
         spin_lock = new SpinLock();
     }
 }
Ejemplo n.º 6
0
        public static ServiceLevelAgreement CreateConsistencySla(Consistency cons, int latency, string Name)
        {
            ServiceLevelAgreement sla = new ServiceLevelAgreement(Name);
            SubSLA subSla1            = new SubSLA(latency, cons, 0, 1);

            sla.Add(subSla1);
            return(sla);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a simple SLA with a single desired consistency and a large latency.
        /// This forces reads to be performed at the closest replica with that consistency.
        /// </summary>
        /// <param name="cons"></param>
        /// <returns></returns>
        public static ServiceLevelAgreement CreateConsistencySla(Consistency cons)
        {
            ServiceLevelAgreement sla = new ServiceLevelAgreement(cons.ToString("g"));
            SubSLA subSla1            = new SubSLA(2000, cons, 0, 1);

            sla.Add(subSla1);
            return(sla);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns the servers that can provide the desired consistency for the given object.
        /// </summary>
        /// <param name="objectName">Name of the object being read</param>
        /// <param name="consistency">Desired consistency</param>
        /// <param name="bound">Time bound for bounded staleness (in seconds)</param>
        /// <returns>The selected servers.</returns>
        public HashSet <ServerState> SelectServersForConsistency(string objectName, Consistency consistency, int bound)
        {
            HashSet <ServerState> selected;

            switch (consistency)
            {
            case Consistency.Strong:
                selected = SelectServersForStrongConsistency(objectName);
                break;

            case Consistency.ReadMyWrites:
                selected = SelectServersForReadMyWrites(objectName);
                break;

            case Consistency.MonotonicReads:
                selected = SelectServersForMonotonicReads(objectName);
                break;

            case Consistency.Session:
                selected = SelectServersForReadMyWrites(objectName);
                selected.IntersectWith(SelectServersForMonotonicReads(objectName));
                break;

            case Consistency.Causal:
                selected = SelectServersForCausal(objectName);
                break;

            case Consistency.Bounded:
                selected = SelectServersForBoundedStaleness(objectName, bound);
                break;

            case Consistency.BoundedReadMyWrites:
                selected = SelectServersForBoundedStaleness(objectName, bound);
                selected.IntersectWith(SelectServersForReadMyWrites(objectName));
                break;

            case Consistency.BoundedMonotonicReads:
                selected = SelectServersForBoundedStaleness(objectName, bound);
                selected.IntersectWith(SelectServersForMonotonicReads(objectName));
                break;

            case Consistency.BoundedSession:
                selected = SelectServersForBoundedStaleness(objectName, bound);
                selected.IntersectWith(SelectServersForReadMyWrites(objectName));
                selected.IntersectWith(SelectServersForMonotonicReads(objectName));
                break;

            case Consistency.Eventual:
                selected = SelectServersForEventualConsistency(objectName);
                break;

            default:
                selected = SelectServersForStrongConsistency(objectName);
                break;
            }

            return(selected);
        }
Ejemplo n.º 9
0
 /// <inheritdoc/>
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Key.GetHashCode();
         hashCode = (hashCode * 397) ^ (Consistency != null ? Consistency.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Request != null ? Request.GetHashCode() : 0);
         return(hashCode);
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Constructs a new SubSLA.
        /// </summary>
        /// <param name="latency">desired latency (in milliseconds)</param>
        /// <param name="consistency">desired consistency</param>
        /// <param name="bound">time-bound for boudned staleness (in seconds)</param>
        /// <param name="utility">value of meeting this SubSLA</param>
        public SubSLA(int latency, Consistency consistency, int bound = 0, float utility = 1.0F)
        {
            this.latency     = latency;
            this.consistency = consistency;
            this.bound       = bound;
            this.utility     = utility;

            this.NumberOfHits   = 0;
            this.NumberOfMisses = 0;
        }
Ejemplo n.º 11
0
 public IndexTypeBase(IIndex index, string name = null, Consistency defaultConsistency = Consistency.Eventual)
 {
     Name  = name ?? _typeName;
     Index = index ?? throw new ArgumentNullException(nameof(index));
     Type  = typeof(T);
     DefaultConsistency = defaultConsistency;
     _queryBuilder      = new Lazy <IElasticQueryBuilder>(CreateQueryBuilder);
     _queryParser       = new Lazy <ElasticQueryParser>(CreateQueryParser);
     _aliasMap          = new Lazy <AliasMap>(GetAliasMap);
 }
 public override async Task WriteMessages(string database, IEnumerable<WriteMessage> messages, Consistency? consistency = null, string retentionPolicy = null, DateTime? timestamp = null, TimePrecision? precision = null)
 {
     using (var msg = new HttpRequestMessage(HttpMethod.Post, CreateUrl("/write", database, null, null, consistency, retentionPolicy)))
     {
         msg.Content = new StringContent(string.Join("\n", messages.Select(x => x.ToString(timestamp, precision))), Encoding.UTF8);
         using (var response = await _client.SendAsync(msg, HttpCompletionOption.ResponseHeadersRead, CancellationToken.None).ConfigureAwait(false))
         {
             response.ValidateHttpResponse(HttpStatusCode.NoContent, true);
         }
     }
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Returns an indication of whether reads should be directed to the primary replica in order to obtain the desired consistency.
        /// </summary>
        /// <param name="objectName">Name of the object being read</param>
        /// <param name="consistency">Desired consistency</param>
        /// <param name="bound">Time bound for bounded staleness (in seconds)</param>
        /// <returns>Whether to read from the primary.</returns>
        public bool MustUsePrimary(string objectName, Consistency consistency, int bound)
        {
            HashSet <ServerState> set;

            set = SelectServersForConsistency(objectName, consistency, bound);
            if (set.Count == 1 && config.PrimaryServers.Contains(set.SingleOrDefault().Name))
            {
                // the primary is the only server in the selected set
                return(true);
            }
            return(false);
        }
Ejemplo n.º 14
0
 public static CodeAttributeDeclaration ReliabilityContractDeclaration(Consistency consistency, Cer cer)
 {
     return(new CodeAttributeDeclaration(
                new CodeTypeReference(typeof(ReliabilityContractAttribute)),
                new CodeAttributeArgument(
                    new CodePropertyReferenceExpression(
                        new CodeTypeReferenceExpression(typeof(Consistency)),
                        consistency.ToString())),
                new CodeAttributeArgument(
                    new CodePropertyReferenceExpression(
                        new CodeTypeReferenceExpression(typeof(Cer)),
                        cer.ToString()))));
 }
        private static Refresh ToRefresh(Consistency mode)
        {
            if (mode == Consistency.Immediate)
            {
                return(Refresh.True);
            }
            if (mode == Consistency.Wait)
            {
                return(Refresh.WaitFor);
            }

            return(Refresh.False);
        }
Ejemplo n.º 16
0
        private static void InitializeModel(DishViewModel model, Consistency consistency, Models.Type type)
        {
            model.DishTypes        = new List <Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>();
            model.ConsistencyTypes = new List <Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>();

            var types = EnumUtil.EnumToList <Models.Type>(Convert.ToInt32(type));

            model.DishTypes.AddRange(types);

            var consistencyTypes = EnumUtil.EnumToList <Models.Consistency>(Convert.ToInt32(consistency));

            model.ConsistencyTypes.AddRange(consistencyTypes);
        }
        internal static string GetQueryParameter(this Consistency that)
        {
            switch (that)
            {
            case Consistency.One:
                return("one");

            case Consistency.Quorum:
                return("quorum");

            case Consistency.All:
                return("all");

            case Consistency.Any:
                return("any");

            default:
                throw new ArgumentException("Invalid parameter value.", nameof(that));
            }
        }
 public ReliabilityContractAttribute(Consistency consistencyGuarantee, System.Runtime.ConstrainedExecution.Cer cer)
 {
     this._consistency = consistencyGuarantee;
     this._cer         = cer;
 }
 public ReliabilityContractAttribute(Consistency consistencyGuarantee, Cer cer)
 {
     _consistency = consistencyGuarantee;
     _cer = cer; 
 }
 partial void UpdateConsistency(Consistency instance);
Ejemplo n.º 21
0
 public ReliabilityContractAttribute
     (Consistency consistencyGuarantee, CER cer)
 {
     this.consistencyGuarantee = consistencyGuarantee;
     this.cer = cer;
 }
 /// <summary>Initializes a new instance of the <see cref="T:System.Runtime.ConstrainedExecution.ReliabilityContractAttribute" /> class with the specified <see cref="T:System.Runtime.ConstrainedExecution.Consistency" /> guarantee and <see cref="T:System.Runtime.ConstrainedExecution.Cer" /> value.</summary><param name="consistencyGuarantee">One of the <see cref="T:System.Runtime.ConstrainedExecution.Consistency" /> values. </param><param name="cer">One of the <see cref="T:System.Runtime.ConstrainedExecution.Cer" /> values. </param>
 public ReliabilityContractAttribute(Consistency consistencyGuarantee, Cer cer)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 23
0
 public UpdateDescriptor <T> Concistency(Consistency consistency)
 {
     this._Consistency = consistency;
     return(this);
 }
	public ReliabilityContractAttribute
				(Consistency consistencyGuarantee, CER cer)
			{
				this.consistencyGuarantee = consistencyGuarantee;
				this.cer = cer;
			}
 public ReliabilityContractAttribute(Consistency consistencyGuarantee, System.Runtime.ConstrainedExecution.Cer cer)
 {
     this._consistency = consistencyGuarantee;
     this._cer = cer;
 }
 partial void DeleteConsistency(Consistency instance);
 partial void UpdateConsistency(Consistency instance);
 partial void InsertConsistency(Consistency instance);
 public ReliabilityContractAttribute (Consistency consistency, CER cer)
 {
         this.consistency = consistency;
         this.cer = cer;
 }
        protected string CreateUrl(string path, string database = null, string query = null, TimePrecision? timePrecision = null, Consistency? consistency = null, string retentionPolicy = null, TimePrecision? resultPrecision = null)
        {
            var queryString = new StringBuilder("?");

            if (!string.IsNullOrEmpty(query))
            {
                queryString.Append("q=" + Uri.EscapeDataString(query.StripWhitespace()) + "&");
            }

            if (!string.IsNullOrEmpty(database))
            {
                queryString.Append("db=" + Uri.EscapeDataString(database.FormatIdentifier()) + "&");
            }

            if (retentionPolicy != null)
            {
                queryString.Append("rp=" + Uri.EscapeDataString(retentionPolicy.FormatIdentifier()) + "&");
            }

            if (!string.IsNullOrEmpty(Settings.Username) && !string.IsNullOrEmpty(Settings.Password))
            {
                queryString.Append("u=" + Uri.EscapeDataString(Settings.Username.Trim()) + "&");
                queryString.Append("p=" + Uri.EscapeDataString(Settings.Password.Trim()) + "&");
            }

            if (timePrecision.HasValue)
            {
                switch (timePrecision)
                {
                    case TimePrecision.Nanosecond:
                        // This is the default precision
                        queryString.Append("precision=n&");
                        break;
                    case TimePrecision.Microsecond:
                        queryString.Append("precision=u&");
                        break;
                    case TimePrecision.Millisecond:
                        queryString.Append("precision=ms&");
                        break;
                    case TimePrecision.Second:
                        queryString.Append("precision=s&");
                        break;
                    case TimePrecision.Minute:
                        queryString.Append("precision=m&");
                        break;
                    case TimePrecision.Hour:
                        queryString.Append("precision=h&");
                        break;
                }
            }

            if (consistency.HasValue)
            {
                switch (consistency)
                {
                    case Consistency.One:
                        queryString.Append("consistency=one&");
                        break;
                    case Consistency.Quorum:
                        queryString.Append("consistency=quorum&");
                        break;
                    case Consistency.All:
                        queryString.Append("consistency=all&");
                        break;
                    case Consistency.Any:
                        queryString.Append("consistency=any&");
                        break;
                }
            }

            if (resultPrecision.HasValue)
            {
                switch (resultPrecision.Value)
                {
                    case TimePrecision.Nanosecond:
                        // This is the default precision
                        queryString.Append("epoch=n&");
                        break;
                    case TimePrecision.Microsecond:
                        queryString.Append("epoch=u&");
                        break;
                    case TimePrecision.Millisecond:
                        queryString.Append("epoch=ms&");
                        break;
                    case TimePrecision.Second:
                        queryString.Append("epoch=s&");
                        break;
                    case TimePrecision.Minute:
                        queryString.Append("epoch=m&");
                        break;
                    case TimePrecision.Hour:
                        queryString.Append("epoch=h&");
                        break;
                }
            }

            if (queryString.Length > 1)
            {
                queryString.Length -= 1;
            }
            else
            {
                queryString.Length = 0;
            }

            return string.Format("{0}://{1}:{2}{3}{4}",
                Settings.UseHttps ? "https" : "http",
                Settings.Host,
                Settings.Port,
                path.StartsWith("/") ? path : "/" + path,
                queryString);
        }
Ejemplo n.º 31
0
        public WriteOptions SetConsistency(Consistency value)
        {
            Consistency = value;

            return this;
        }
Ejemplo n.º 32
0
 public BulkUpdateDescriptor <T, K> Consistency(Consistency consistency)
 {
     this._Consistency = consistency;
     return(this);
 }
 public abstract Task WriteMessage(string database, WriteMessage message, Consistency? consistency = null, string retentionPolicy = null, DateTime? timestamp = null, TimePrecision? precision = null);
 public static Consistency GetConsistency(this ICommandOptions options, Consistency defaultMode = Consistency.Eventual)
 {
     return(options.SafeGetOption(ConsistencyOptionsExtensions.ConsistencyModeKey, defaultMode));
 }
Ejemplo n.º 35
0
 public InfluxDBClient(IRequestProcessor requestProcessor, ITimestampGenerator timestampGenerator, string database, Consistency defaultConsistency) : this(database, defaultConsistency)
 {
     RequestProcessor = requestProcessor;
     TimestampGenerator = timestampGenerator;
 }
Ejemplo n.º 36
0
 public BulkDeleteDescriptor <T> Consistency(Consistency consistency)
 {
     this._Consistency = consistency;
     return(this);
 }
Ejemplo n.º 37
0
 public InfluxDBClient(string host, int port, bool useHttps, string username, string password, string database, ITimestampGenerator timestampGenerator, Consistency defaultConsistency) : this(database, defaultConsistency)
 {
     RequestProcessor = new HttpClientRequestProcessor(new RequestProcessorSettings(host, port, useHttps, username, password));
     TimestampGenerator = timestampGenerator;
 }
 partial void InsertConsistency(Consistency instance);
Ejemplo n.º 39
0
 public InfluxDBClient(string host, int port, bool useHttps, string username, string password, string database, Consistency defaultConsistency, TimePrecision timestampPrecision = TimePrecision.Nanosecond) : this(database, defaultConsistency)
 {
     RequestProcessor = new HttpClientRequestProcessor(new RequestProcessorSettings(host, port, useHttps, username, password));
     TimestampGenerator = new AdaptiveTimestampGenerator(timestampPrecision);
 }
 partial void DeleteConsistency(Consistency instance);
Ejemplo n.º 41
0
 public async Task WriteMessages(IEnumerable<WriteMessage> messages, Consistency? consistency = null, string retentionPolicy = null)
 {
     await RequestProcessor.WriteMessages(Database, messages, consistency ?? DefaultConsistency, retentionPolicy, TimestampGenerator.GetTimestamp(), TimestampGenerator.Precision).ConfigureAwait(false);
 }
Ejemplo n.º 42
0
 public ReliabilityContractAttribute(Consistency consistency, CER cer)
 {
     this.consistency = consistency;
     this.cer         = cer;
 }
Ejemplo n.º 43
0
 void Out(out Consistency c)
 {
     c       = new Consistency();
     c.Field = 0;
 }
Ejemplo n.º 44
0
 public ReliabilityContractAttribute(Consistency consistencyGuarantee, Cer cer)
 {
     _consistency = consistencyGuarantee;
     _cer         = cer;
 }
 public static Refresh GetRefreshMode(this ICommandOptions options, Consistency defaultMode = Consistency.Eventual)
 {
     return(ToRefresh(options.GetConsistency(defaultMode)));
 }
Ejemplo n.º 46
0
 private InfluxDBClient(string database, Consistency defaultConsistency)
 {
     Database = database;
     DefaultConsistency = defaultConsistency;
 }
 public abstract Task WriteMessages(string database, IEnumerable<WriteMessage> messages, Consistency? consistency = null, string retentionPolicy = null, DateTime? timestamp = null, TimePrecision? precision = null);