-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
leveldb: add message, config and metrics (#3272)
- Loading branch information
Showing
19 changed files
with
647 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2021 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, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package message | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pingcap/ticdc/cdc/sorter/encoding" | ||
Iterator "github.com/syndtr/goleveldb/leveldb/iterator" | ||
lutil "github.com/syndtr/goleveldb/leveldb/util" | ||
"golang.org/x/sync/semaphore" | ||
) | ||
|
||
// Task is a leveldb actor task. It carries write and read request. | ||
type Task struct { | ||
UID uint32 | ||
TableID uint64 | ||
|
||
// encoded key -> serde.marshal(event) | ||
// If a value is empty, it deletes the key/value entry in leveldb. | ||
Events map[Key][]byte | ||
// Must be buffered channel to avoid blocking. | ||
IterCh chan LimitedIterator `json:"-"` // Make Task JSON printable. | ||
Irange *lutil.Range | ||
// Set NeedIter whenever caller wants to read something from an iterator. | ||
NeedIter bool | ||
} | ||
|
||
// Key is the key that is written to leveldb. | ||
type Key string | ||
|
||
// String returns a pretty printed string. | ||
func (k Key) String() string { | ||
uid, tableID, startTs, CRTs := encoding.DecodeKey([]byte(k)) | ||
return fmt.Sprintf( | ||
"uid: %d, tableID: %d, startTs: %d, CRTs: %d", | ||
uid, tableID, startTs, CRTs) | ||
} | ||
|
||
// LimitedIterator is a wrapper of leveldb iterator that has a sema to limit | ||
// the total number of open iterators. | ||
type LimitedIterator struct { | ||
Iterator.Iterator | ||
Sema *semaphore.Weighted | ||
} |
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,37 @@ | ||
// Copyright 2021 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, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package message | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pingcap/ticdc/cdc/model" | ||
"github.com/pingcap/ticdc/cdc/sorter/encoding" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPrint(t *testing.T) { | ||
t.Parallel() | ||
event := model.NewPolymorphicEvent(&model.RawKVEntry{ | ||
OpType: model.OpTypeDelete, | ||
Key: []byte{1}, | ||
StartTs: 3, | ||
CRTs: 4, | ||
}) | ||
|
||
require.Equal(t, "uid: 1, tableID: 2, startTs: 3, CRTs: 4", | ||
Key(encoding.EncodeKey(1, 2, event)).String()) | ||
require.Equal(t, "uid: 1, tableID: 2, startTs: 0, CRTs: 3", | ||
Key(encoding.EncodeTsKey(1, 2, 3)).String()) | ||
} |
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,50 @@ | ||
// Copyright 2021 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, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package leveldb | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
var ( | ||
sorterWriteBytesHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{ | ||
Namespace: "ticdc", | ||
Subsystem: "sorter", | ||
Name: "leveldb_write_bytes", | ||
Help: "Bucketed histogram of sorter write batch bytes", | ||
Buckets: prometheus.ExponentialBuckets(16, 2.0, 20), | ||
}, []string{"capture", "id"}) | ||
|
||
sorterWriteDurationHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{ | ||
Namespace: "ticdc", | ||
Subsystem: "sorter", | ||
Name: "leveldb_write_duration_seconds", | ||
Help: "Bucketed histogram of sorter write duration", | ||
Buckets: prometheus.ExponentialBuckets(0.004, 2.0, 20), | ||
}, []string{"capture", "id"}) | ||
|
||
sorterCleanupKVCounter = prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
Namespace: "ticdc", | ||
Subsystem: "sorter", | ||
Name: "leveldb_cleanup_kv_total", | ||
Help: "The total number of cleaned up kv entries", | ||
}, []string{"capture", "id"}) | ||
) | ||
|
||
// InitMetrics registers all metrics in this file | ||
func InitMetrics(registry *prometheus.Registry) { | ||
registry.MustRegister(sorterWriteDurationHistogram) | ||
registry.MustRegister(sorterWriteBytesHistogram) | ||
registry.MustRegister(sorterCleanupKVCounter) | ||
} |
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,69 @@ | ||
// Copyright 2021 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, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package sorter | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
var ( | ||
// SorterEventCount is the metric that counts events output by the sorter. | ||
SorterEventCount = prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
Namespace: "ticdc", | ||
Subsystem: "sorter", | ||
Name: "event_count", | ||
Help: "The number of events output by the sorter", | ||
}, []string{"capture", "changefeed", "type"}) | ||
|
||
// SorterResolvedTsGauge is the metric that records sorter resolved ts. | ||
SorterResolvedTsGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{ | ||
Namespace: "ticdc", | ||
Subsystem: "sorter", | ||
Name: "resolved_ts_gauge", | ||
Help: "the resolved ts of the sorter", | ||
}, []string{"capture", "changefeed"}) | ||
|
||
// SorterInMemoryDataSizeGauge is the metric that records sorter memory usage. | ||
SorterInMemoryDataSizeGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{ | ||
Namespace: "ticdc", | ||
Subsystem: "sorter", | ||
Name: "in_memory_data_size_gauge", | ||
Help: "The amount of pending data stored in-memory by the sorter", | ||
}, []string{"capture", "id"}) | ||
|
||
// SorterOnDiskDataSizeGauge is the metric that records sorter disk usage. | ||
SorterOnDiskDataSizeGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{ | ||
Namespace: "ticdc", | ||
Subsystem: "sorter", | ||
Name: "on_disk_data_size_gauge", | ||
Help: "The amount of pending data stored on-disk by the sorter", | ||
}, []string{"capture", "id"}) | ||
|
||
// SorterOpenFileCountGauge is the metric that records sorter open files. | ||
SorterOpenFileCountGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{ | ||
Namespace: "ticdc", | ||
Subsystem: "sorter", | ||
Name: "open_file_count_gauge", | ||
Help: "The number of open file descriptors held by the sorter", | ||
}, []string{"capture", "id"}) | ||
) | ||
|
||
// InitMetrics registers all metrics in this file | ||
func InitMetrics(registry *prometheus.Registry) { | ||
registry.MustRegister(SorterEventCount) | ||
registry.MustRegister(SorterResolvedTsGauge) | ||
registry.MustRegister(SorterInMemoryDataSizeGauge) | ||
registry.MustRegister(SorterOnDiskDataSizeGauge) | ||
registry.MustRegister(SorterOpenFileCountGauge) | ||
} |
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
Oops, something went wrong.