internal UdtMappingDefinitions(IInternalSession session, ISerializerManager serializer)
 {
     _udtByNetType = new ConcurrentDictionary <Type, UdtMap>();
     _cluster      = session.InternalCluster;
     _session      = session;
     _serializer   = serializer;
 }
 internal PreparedStatement(RowSetMetadata variablesRowsMetadata, byte[] id, ResultMetadata resultMetadata, string cql,
                            string keyspace, ISerializerManager serializer)
 {
     _variablesRowsMetadata = variablesRowsMetadata;
     _resultMetadata        = resultMetadata;
     Id                 = id;
     Cql                = cql;
     Keyspace           = keyspace;
     _serializerManager = serializer;
 }
 private static PreparedStatement GetPrepared(
     byte[] queryId = null, ISerializerManager serializerManager = null, RowSetMetadata rowSetMetadata = null)
 {
     return(new PreparedStatement(
                null,
                queryId,
                new ResultMetadata(new byte[16], rowSetMetadata),
                "DUMMY QUERY",
                null,
                serializerManager ?? RequestHandlerTests.SerializerManager));
 }
Example #4
0
        public async Task <IConnection> ChangeProtocolVersion(
            Configuration config,
            ISerializerManager serializer,
            ProtocolVersion nextVersion,
            IConnection previousConnection,
            UnsupportedProtocolVersionException ex = null,
            ProtocolVersion?previousVersion        = null)
        {
            if (!nextVersion.IsSupported() || nextVersion == previousVersion)
            {
                nextVersion = nextVersion.GetLowerSupported();
            }

            if (nextVersion == 0)
            {
                if (ex != null)
                {
                    // We have downgraded the version until is 0 and none of those are supported
                    throw ex;
                }

                // There was no exception leading to the downgrade, signal internal error
                throw new DriverInternalError("Connection was unable to STARTUP using protocol version 0");
            }

            ControlConnection.Logger.Info(ex != null
                ? $"{ex.Message}, trying with version {nextVersion:D}"
                : $"Changing protocol version to {nextVersion:D}");

            serializer.ChangeProtocolVersion(nextVersion);

            previousConnection.Dispose();

            var c = config.ConnectionFactory.CreateUnobserved(
                serializer.GetCurrentSerializer(),
                previousConnection.EndPoint,
                config);

            try
            {
                await c.Open().ConfigureAwait(false);

                return(c);
            }
            catch
            {
                c.Dispose();
                throw;
            }
        }
 public HostConnectionPool(Host host, Configuration config, ISerializerManager serializerManager, IObserverFactory observerFactory)
 {
     _host                     = host;
     _host.Down               += OnHostDown;
     _host.Up                 += OnHostUp;
     _host.DistanceChanged    += OnDistanceChanged;
     _config                   = config ?? throw new ArgumentNullException(nameof(config));
     _poolingOptions           = config.GetOrCreatePoolingOptions(serializerManager.CurrentProtocolVersion);
     _maxRequestsPerConnection = _poolingOptions.GetMaxRequestsPerConnection();
     _serializerManager        = serializerManager;
     _observerFactory          = observerFactory;
     _timer                    = config.Timer;
     _reconnectionSchedule     = config.Policies.ReconnectionPolicy.NewSchedule();
     _expectedConnectionLength = 1;
 }
Example #6
0
        public async Task <IConnection> NegotiateVersionAsync(
            Configuration config,
            Metadata metadata,
            IConnection connection,
            ISerializerManager serializer)
        {
            var commonVersion = serializer.CurrentProtocolVersion.GetHighestCommon(metadata.Hosts);

            if (commonVersion != serializer.CurrentProtocolVersion)
            {
                // Current connection will be closed and reopened
                connection = await ChangeProtocolVersion(
                    config, serializer, commonVersion, connection).ConfigureAwait(false);
            }

            return(connection);
        }
Example #7
0
        /// <inheritdoc />
        async Task <PreparedStatement> IInternalCluster.Prepare(
            IInternalSession session, ISerializerManager serializerManager, PrepareRequest request)
        {
            var lbp     = session.Cluster.Configuration.DefaultRequestOptions.LoadBalancingPolicy;
            var handler = InternalRef.Configuration.PrepareHandlerFactory.CreatePrepareHandler(serializerManager, this);
            var ps      = await handler.Prepare(request, session, lbp.NewQueryPlan(session.Keyspace, null).GetEnumerator()).ConfigureAwait(false);

            var psAdded = InternalRef.PreparedQueries.GetOrAdd(ps.Id, ps);

            if (ps != psAdded)
            {
                PrepareHandler.Logger.Warning("Re-preparing already prepared query is generally an anti-pattern and will likely " +
                                              "affect performance. Consider preparing the statement only once. Query='{0}'", ps.Cql);
                ps = psAdded;
            }

            return(ps);
        }
Example #8
0
        private static Mock <ISession> GetSessionMock(ISerializerManager serializer = null)
        {
            if (serializer == null)
            {
                serializer = new SerializerManager(ProtocolVersion.MaxSupported);
            }
            var sessionMock = new Mock <ISession>(MockBehavior.Strict);
            var config      = new Configuration();
            var metadata    = new Metadata(config);
            var ccMock      = new Mock <IControlConnection>(MockBehavior.Strict);

            ccMock.Setup(cc => cc.Serializer).Returns(serializer);
            metadata.ControlConnection = ccMock.Object;
            var clusterMock = new Mock <ICluster>();

            clusterMock.Setup(c => c.Metadata).Returns(metadata);
            clusterMock.Setup(c => c.Configuration).Returns(config);
            sessionMock.Setup(s => s.Cluster).Returns(clusterMock.Object);
            return(sessionMock);
        }
 public IPrepareHandler CreatePrepareHandler(
     ISerializerManager serializerManager, IInternalCluster cluster)
 {
     return(new PrepareHandler(serializerManager, cluster, CreateReprepareHandler()));
 }
Example #10
0
 private static Mock <Connection> GetConnectionMock(Configuration config = null, ISerializerManager serializer = null)
 {
     config = config ?? new Configuration();
     return(new Mock <Connection>(
                MockBehavior.Loose,
                serializer?.GetCurrentSerializer() ?? new SerializerManager(ProtocolVersion.MaxSupported).GetCurrentSerializer(),
                new ConnectionEndPoint(ConnectionTests.Address, null),
                config,
                new StartupRequestFactory(config.StartupOptionsFactory),
                NullConnectionObserver.Instance));
 }
Example #11
0
 public Task <IInternalSession> CreateSessionAsync(
     IInternalCluster cluster, string keyspace, ISerializerManager serializer, string sessionName)
 {
     return(Task.FromResult(
                new Session(cluster, cluster.Configuration, keyspace, serializer, sessionName).InternalRef));
 }
Example #12
0
 public PrepareHandler(ISerializerManager serializerManager, IInternalCluster cluster, IReprepareHandler reprepareHandler)
 {
     _serializerManager = serializerManager;
     _cluster           = cluster;
     _reprepareHandler  = reprepareHandler;
 }
 public Task <IConnection> NegotiateVersionAsync(Configuration config, Metadata metadata, IConnection connection, ISerializerManager serializer)
 {
     return(Task.FromResult(connection));
 }
 public Task <IConnection> ChangeProtocolVersion(Configuration config, ISerializerManager serializer, ProtocolVersion nextVersion, IConnection previousConnection,
                                                 UnsupportedProtocolVersionException ex = null, ProtocolVersion?previousVersion = null)
 {
     return(Task.FromResult(previousConnection));
 }
 public IHostConnectionPool Create(Host host, Configuration config, ISerializerManager serializerManager, IObserverFactory observerFactory)
 {
     return(new HostConnectionPool(host, config, serializerManager, observerFactory));
 }