forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
statistics: move StatsUsage and TableDelta into new package (pingcap#…
…47238) ref pingcap#46905
- Loading branch information
1 parent
29ba912
commit 48f6b35
Showing
7 changed files
with
190 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2023 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package usage | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
|
||
"github.com/pingcap/tidb/parser/model" | ||
) | ||
|
||
// StatsUsage maps (tableID, columnID) to the last time when the column stats are used(needed). | ||
// All methods of it are thread-safe. | ||
type StatsUsage struct { | ||
usage map[model.TableItemID]time.Time | ||
lock sync.RWMutex | ||
} | ||
|
||
// NewStatsUsage creates a new StatsUsage. | ||
func NewStatsUsage() *StatsUsage { | ||
return &StatsUsage{ | ||
usage: make(map[model.TableItemID]time.Time), | ||
} | ||
} | ||
|
||
// Reset resets the StatsUsage. | ||
func (m *StatsUsage) Reset() { | ||
m.lock.Lock() | ||
defer m.lock.Unlock() | ||
m.usage = make(map[model.TableItemID]time.Time) | ||
} | ||
|
||
// GetUsageAndReset gets the usage and resets the StatsUsage. | ||
func (m *StatsUsage) GetUsageAndReset() map[model.TableItemID]time.Time { | ||
m.lock.Lock() | ||
defer m.lock.Unlock() | ||
ret := m.usage | ||
m.usage = make(map[model.TableItemID]time.Time) | ||
return ret | ||
} | ||
|
||
// Merge merges the usageMap into the StatsUsage. | ||
func (m *StatsUsage) Merge(other map[model.TableItemID]time.Time) { | ||
if len(other) == 0 { | ||
return | ||
} | ||
m.lock.Lock() | ||
defer m.lock.Unlock() | ||
for id, t := range other { | ||
if mt, ok := m.usage[id]; !ok || mt.Before(t) { | ||
m.usage[id] = t | ||
} | ||
} | ||
} |
Oops, something went wrong.