@@ -118,13 +118,14 @@ func NewNomsStats(sourceDb, statsDb dsess.SqlDatabase) *NomsStatsDatabase {
118118type dbStats map [sql.StatQualifier ]* statspro.DoltStats
119119
120120type NomsStatsDatabase struct {
121- mu * sync.Mutex
122- destDb dsess.SqlDatabase
123- sourceDb dsess.SqlDatabase
124- stats []dbStats
125- branches []string
126- latestTableRoots []map [string ]hash.Hash
127- dirty []* prolly.MutableMap
121+ mu * sync.Mutex
122+ destDb dsess.SqlDatabase
123+ sourceDb dsess.SqlDatabase
124+ stats []dbStats
125+ branches []string
126+ tableHashes []map [string ]hash.Hash
127+ schemaHashes []map [string ]hash.Hash
128+ dirty []* prolly.MutableMap
128129}
129130
130131var _ statspro.Database = (* NomsStatsDatabase )(nil )
@@ -158,7 +159,8 @@ func (n *NomsStatsDatabase) LoadBranchStats(ctx *sql.Context, branch string) err
158159 n .branches = append (n .branches , branch )
159160 n .stats = append (n .stats , doltStats )
160161 n .dirty = append (n .dirty , nil )
161- n .latestTableRoots = append (n .latestTableRoots , make (map [string ]hash.Hash ))
162+ n .tableHashes = append (n .tableHashes , make (map [string ]hash.Hash ))
163+ n .schemaHashes = append (n .schemaHashes , make (map [string ]hash.Hash ))
162164 return nil
163165}
164166
@@ -223,7 +225,8 @@ func (n *NomsStatsDatabase) SetStat(ctx context.Context, branch string, qual sql
223225func (n * NomsStatsDatabase ) trackBranch (ctx context.Context , branch string ) error {
224226 n .branches = append (n .branches , branch )
225227 n .stats = append (n .stats , make (dbStats ))
226- n .latestTableRoots = append (n .latestTableRoots , make (map [string ]hash.Hash ))
228+ n .tableHashes = append (n .tableHashes , make (map [string ]hash.Hash ))
229+ n .schemaHashes = append (n .schemaHashes , make (map [string ]hash.Hash ))
227230
228231 kd , vd := schema .StatsTableDoltSchema .GetMapDescriptors ()
229232 newMap , err := prolly .NewMapFromTuples (ctx , n .destDb .DbData ().Ddb .NodeStore (), kd , vd )
@@ -268,7 +271,7 @@ func (n *NomsStatsDatabase) DeleteBranchStats(ctx *sql.Context, branch string, f
268271 n .branches = append (n .branches [:i ], n .branches [i + 1 :]... )
269272 n .dirty = append (n .dirty [:i ], n .dirty [i + 1 :]... )
270273 n .stats = append (n .stats [:i ], n .stats [i + 1 :]... )
271- n .latestTableRoots = append (n .latestTableRoots [:i ], n .latestTableRoots [i + 1 :]... )
274+ n .tableHashes = append (n .tableHashes [:i ], n .tableHashes [i + 1 :]... )
272275 }
273276 }
274277 if flush {
@@ -339,23 +342,45 @@ func (n *NomsStatsDatabase) Flush(ctx context.Context, branch string) error {
339342 return nil
340343}
341344
342- func (n * NomsStatsDatabase ) GetLatestHash (branch , tableName string ) hash.Hash {
345+ func (n * NomsStatsDatabase ) GetTableHash (branch , tableName string ) hash.Hash {
343346 n .mu .Lock ()
344347 defer n .mu .Unlock ()
345348 for i , b := range n .branches {
346349 if strings .EqualFold (branch , b ) {
347- return n.latestTableRoots [i ][tableName ]
350+ return n.tableHashes [i ][tableName ]
348351 }
349352 }
350353 return hash.Hash {}
351354}
352355
353- func (n * NomsStatsDatabase ) SetLatestHash (branch , tableName string , h hash.Hash ) {
356+ func (n * NomsStatsDatabase ) SetTableHash (branch , tableName string , h hash.Hash ) {
354357 n .mu .Lock ()
355358 defer n .mu .Unlock ()
356359 for i , b := range n .branches {
357360 if strings .EqualFold (branch , b ) {
358- n.latestTableRoots [i ][tableName ] = h
361+ n.tableHashes [i ][tableName ] = h
362+ break
363+ }
364+ }
365+ }
366+
367+ func (n * NomsStatsDatabase ) GetSchemaHash (branch , tableName string ) hash.Hash {
368+ n .mu .Lock ()
369+ defer n .mu .Unlock ()
370+ for i , b := range n .branches {
371+ if strings .EqualFold (branch , b ) {
372+ return n.schemaHashes [i ][tableName ]
373+ }
374+ }
375+ return hash.Hash {}
376+ }
377+
378+ func (n * NomsStatsDatabase ) SetSchemaHash (branch , tableName string , h hash.Hash ) {
379+ n .mu .Lock ()
380+ defer n .mu .Unlock ()
381+ for i , b := range n .branches {
382+ if strings .EqualFold (branch , b ) {
383+ n.schemaHashes [i ][tableName ] = h
359384 break
360385 }
361386 }
0 commit comments