Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
added function to get stopsyncversion from the relaydb instead of cti…
Browse files Browse the repository at this point in the history
…ds and pass that into the mysqldatautils
  • Loading branch information
zerobfd authored and Clayton Pence committed Feb 3, 2014
1 parent 0525f04 commit d514a08
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
11 changes: 10 additions & 1 deletion TeslaSQL/Agents/MasterMaintenance.cs
Expand Up @@ -38,7 +38,16 @@ public MasterMaintenance(IDataUtils dataUtils, IDataUtils destDataUtils, Logger

public override void Run() {
var chopDate = DateTime.Now - new TimeSpan(Config.ChangeRetentionHours, 0, 0);
var CTIDs = destDataUtils.GetOldCTIDsMaster(Config.RelayDB, chopDate);
IEnumerable<long> CTIDs;
if (Config.MasterType == SqlFlavor.MySQL)
{
var temp = (MSSQLDataUtils)destDataUtils;
CTIDs = temp.GetOldStopSyncMaster(Config.RelayDB, chopDate);
}
else
{
CTIDs = destDataUtils.GetOldCTIDsMaster(Config.RelayDB, chopDate);
}
var tables = sourceDataUtils.GetTables(Config.MasterCTDB);
if (tables.Count() > 0) {
logger.Log("Deleting {" + string.Join(",", CTIDs) + "} from { " + string.Join(",", tables.Select(t => t.name)) + "}", LogLevel.Debug);
Expand Down
14 changes: 14 additions & 0 deletions TeslaSQL/DataUtils/MSSQLDataUtils.cs
Expand Up @@ -1241,6 +1241,20 @@ THEN DELETE
var cmd = new SqlCommand(sql);
SqlNonQuery(consolidatedDB, cmd);
}

public IEnumerable<long> GetOldStopSyncMaster(string dbName, DateTime chopDate)
{
string sql = "SELECT syncStopVersion AS ctid FROM [dbo].[tblCTVersion] WHERE syncStartTime < @chopDate";
var cmd = new SqlCommand(sql);
cmd.Parameters.Add("@chopDate", SqlDbType.DateTime).Value = chopDate;
var res = SqlQuery(dbName, cmd);
var CTIDs = new List<long>();
foreach (DataRow row in res.Rows)
{
CTIDs.Add(row.Field<long>("ctid"));
}
return CTIDs;
}

}
}
3 changes: 2 additions & 1 deletion TeslaSQL/DataUtils/MySQLDataUtils.cs
Expand Up @@ -938,7 +938,7 @@ public IEnumerable<TTable> GetTables(string dbName)

public IEnumerable<long> GetOldCTIDsMaster(string dbName, DateTime chopDate)
{
string sql = "SELECT syncStopVersion AS ctid FROM tblCTVersion WHERE syncStartTime < @chopDate";
string sql = "SELECT ctid FROM tblCTVersion WHERE syncStartTime < @chopDate";
var cmd = new MySqlCommand(sql);
cmd.Parameters.Add("@chopDate", MySqlDbType.Timestamp).Value = chopDate.ToUniversalTime();
DataTable res = MySqlQuery(dbName, cmd);
Expand Down Expand Up @@ -1330,5 +1330,6 @@ public bool CleanupTriggerTable(string dbName, string tableName, DateTime chopDa
return true;

}

}
}

0 comments on commit d514a08

Please sign in to comment.