Ejemplo n.º 1
0
        /// <summary>
        /// 放到Redsi中
        /// </summary>
        /// <param name="statement"></param>
        public static bool Put(SqlStatement statement)
        {
            bool result = false;
            try
            {
                if (!IsUseSyncQueue)
                {
                    return false;
                }
                string key = GetSqlQueueKey(statement.IdentityID);
                byte[] value = ProtoBufUtils.Serialize(statement);
                RedisConnectionPool.Process(client => client.ZAdd(key, DateTime.Now.Ticks, value));
                result = true;
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Sql update queue write error:{0}\r\n{1}", ex, JsonUtils.SerializeCustom(statement));
            }

            return result;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// put error sql
 /// </summary>
 /// <param name="statement"></param>
 /// <returns></returns>
 public static bool PutError(SqlStatement statement)
 {
     bool result = false;
     RedisManager.Process(client =>
     {
         try
         {
             string key = GetStatementKey(statement.IdentityID) + "_error";
             byte[] value = ProtoBufUtils.Serialize(statement);
             client.ZAdd(key, value);
             result = true;
         }
         catch (Exception ex)
         {
             TraceLog.WriteError("Sql statement put to redis error:{0}\r\n{1}", ex, JsonUtils.SerializeCustom(statement));
         }
     });
     return result;
 }
Ejemplo n.º 3
0
        private static void DoProcessSqlSyncQueue(string workingKey, byte[][] bufferBytes)
        {
            try
            {
                bool hasClear = false;
                foreach (var buffer in bufferBytes)
                {
                    DbBaseProvider dbProvider = null;
                    SqlStatement   statement  = null;
                    int            result     = 0;
                    try
                    {
                        statement  = ProtoBufUtils.Deserialize <SqlStatement>(buffer);
                        dbProvider = DbConnectionProvider.CreateDbProvider("", statement.ProviderType,
                                                                           statement.ConnectionString);
                        var paramList = ToSqlParameter(dbProvider, statement.Params);
                        result = dbProvider.ExecuteQuery(statement.CommandType, statement.CommandText, paramList);
                    }
                    catch (DbConnectionException connError)
                    {
                        TraceLog.WriteSqlError("SqlSync Error:{0}\r\nSql>>\r\n{1}", connError,
                                               statement != null ? statement.ToString() : "");
                        if (dbProvider != null)
                        {
                            //modify error: 40 - Could not open a connection to SQL Server
                            dbProvider.ClearAllPools();

                            //resend
                            var paramList = ToSqlParameter(dbProvider, statement.Params);
                            result = dbProvider.ExecuteQuery(statement.CommandType, statement.CommandText, paramList);
                        }
                        else
                        {
                            PutError(buffer, SqlSyncConnErrorQueueKey);
                        }
                    }
                    catch (Exception e)
                    {
                        TraceLog.WriteSqlError("SqlSync Error:{0}\r\nSql>>\r\n{1}", e,
                                               statement != null ? statement.ToString() : "");
                        PutError(buffer);
                        if (!hasClear && dbProvider != null)
                        {
                            //modify error: 40 - Could not open a connection to SQL Server
                            hasClear = true;
                            dbProvider.ClearAllPools();
                        }
                    }
                    finally
                    {
                        if (result > 0)
                        {
                            ProfileManager.ProcessSqlOfMessageQueueTimes(statement != null ? statement.Table : null);
                        }
                        else
                        {
                            ProfileManager.ProcessFailSqlOfMessageQueueTimes(statement != null ? statement.Table : null, 1);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("DoProcessSqlSyncQueue error:{0}", ex);
            }
        }