public void Dispose()
 {
     _docsToRelease.Dispose();
     _docsToWrite.Dispose();
     _messagesToClient.Dispose();
     try
     {
         TcpConnection.Dispose();
     }
     catch (Exception)
     {
     }
 }
        public static void Run(TcpConnectionOptions tcpConnectionOptions)
        {
            var bulkInsertThread = new Thread(() =>
            {
                var logger = LoggingSource.Instance.GetLogger <BulkInsertConnection>(tcpConnectionOptions.DocumentDatabase.Name);
                try
                {
                    using (var bulkInsert = new BulkInsertConnection(tcpConnectionOptions, logger))
                    {
                        bulkInsert.Execute();
                    }
                }
                catch (Exception e)
                {
                    if (logger.IsInfoEnabled)
                    {
                        logger.Info("Failed to process bulk insert run", e);
                    }
                    try
                    {
                        using (var writer = new BlittableJsonTextWriter(tcpConnectionOptions.Context, tcpConnectionOptions.Stream))
                        {
                            tcpConnectionOptions.Context.Write(writer, new DynamicJsonValue
                            {
                                ["Type"]      = "Error",
                                ["Exception"] = e.ToString()
                            });
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                finally
                {
                    tcpConnectionOptions.Dispose();
                    // Thread is going to die, let us release those resources early, instead of waiting for finalizer
                    ByteStringMemoryCache.Clean();
                    tcpConnectionOptions.DocumentDatabase.DocumentsStorage.ContextPool.Clean();
                }
            })
            {
                IsBackground = true,
                Name         = "Bulk Insert Operation"
            };

            bulkInsertThread.Start();
        }
Exemple #3
0
 public void Dispose()
 {
     if (_isDisposed)
     {
         return;
     }
     _isDisposed = true;
     Stats.Dispose();
     try
     {
         TcpConnection.Dispose();
     }
     catch (Exception)
     {
         // ignored
     }
 }
Exemple #4
0
        public static void SendSubscriptionDocuments(TcpConnectionOptions tcpConnectionOptions)
        {
            Task.Run(async() =>
            {
                var connection = new SubscriptionConnection(tcpConnectionOptions);
                tcpConnectionOptions.DisposeOnConnectionClose.Add(connection);
                try
                {
                    if (await connection.InitAsync() == false)
                    {
                        return;
                    }
                    await connection.ProcessSubscriptionAysnc();
                }
                catch (Exception e)
                {
                    if (connection._logger.IsInfoEnabled)
                    {
                        connection._logger.Info($"Failed to process subscription {connection._options?.SubscriptionId} / from client {connection.TcpConnection.TcpClient.Client.RemoteEndPoint}",
                                                e);
                    }
                    try
                    {
                        if (connection.ConnectionException != null)
                        {
                            return;
                        }
                        using (var writer = new BlittableJsonTextWriter(tcpConnectionOptions.Context, tcpConnectionOptions.Stream))
                        {
                            tcpConnectionOptions.Context.Write(writer, new DynamicJsonValue
                            {
                                ["Type"]      = "Error",
                                ["Exception"] = e.ToString()
                            });
                        }
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                }
                finally
                {
                    if (connection._options != null && connection._logger.IsInfoEnabled)
                    {
                        connection._logger.Info($"Finished proccessing subscription {connection._options?.SubscriptionId} / from client {connection.TcpConnection.TcpClient.Client.RemoteEndPoint}");
                    }

                    if (connection.ConnectionException != null)
                    {
                        try
                        {
                            var status = "None";
                            if (connection.ConnectionException is SubscriptionClosedException)
                            {
                                status = "Closed";
                            }

                            using (var writer = new BlittableJsonTextWriter(tcpConnectionOptions.Context, tcpConnectionOptions.Stream))
                            {
                                tcpConnectionOptions.Context.Write(writer, new DynamicJsonValue
                                {
                                    ["Type"]      = "Error",
                                    ["Status"]    = status,
                                    ["Exception"] = connection.ConnectionException.ToString()
                                });
                            }
                        }
                        catch
                        {
                            // ignored
                        }
                    }
                    tcpConnectionOptions.Dispose();
                }
            });
        }