-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
* Add new task: miner_sector_deal_v2
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package miner | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opencensus.io/tag" | ||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/attribute" | ||
|
||
"github.com/filecoin-project/lily/metrics" | ||
"github.com/filecoin-project/lily/model" | ||
) | ||
|
||
type MinerSectorDealV2 struct { | ||
tableName struct{} `pg:"miner_sector_deals_v2"` // nolint: structcheck | ||
|
||
Height int64 `pg:",pk,notnull,use_zero"` | ||
MinerID string `pg:",pk,notnull"` | ||
SectorID uint64 `pg:",pk,use_zero"` | ||
DealID uint64 `pg:",pk,use_zero"` | ||
} | ||
|
||
func (ds *MinerSectorDealV2) Persist(ctx context.Context, s model.StorageBatch, _ model.Version) error { | ||
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "miner_sector_deals_v2")) | ||
metrics.RecordCount(ctx, metrics.PersistModel, 1) | ||
return s.PersistModel(ctx, ds) | ||
} | ||
|
||
type MinerSectorDealListV2 []*MinerSectorDealV2 | ||
|
||
func (ml MinerSectorDealListV2) Persist(ctx context.Context, s model.StorageBatch, _ model.Version) error { | ||
ctx, span := otel.Tracer("").Start(ctx, "MinerSectorDealListV2.Persist") | ||
if span.IsRecording() { | ||
span.SetAttributes(attribute.Int("count", len(ml))) | ||
} | ||
defer span.End() | ||
|
||
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "miner_sector_deals_v2")) | ||
|
||
if len(ml) == 0 { | ||
return nil | ||
} | ||
metrics.RecordCount(ctx, metrics.PersistModel, len(ml)) | ||
return s.PersistModel(ctx, ml) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package v1 | ||
|
||
func init() { | ||
patches.Register( | ||
38, | ||
` | ||
CREATE TABLE {{ .SchemaName | default "public"}}.miner_sector_deals_v2 ( | ||
miner_id text NOT NULL, | ||
sector_id bigint NOT NULL, | ||
deal_id bigint NOT NULL, | ||
height bigint NOT NULL | ||
); | ||
ALTER TABLE ONLY {{ .SchemaName | default "public"}}.miner_sector_deals_v2 ADD CONSTRAINT miner_sector_deals_v2_pkey PRIMARY KEY (height, miner_id, sector_id, deal_id); | ||
CREATE INDEX IF NOT EXISTS miner_sector_deals_height_idx ON {{ .SchemaName | default "public"}}.miner_sector_deals_v2 USING btree (height DESC); | ||
CREATE INDEX IF NOT EXISTS miner_sector_deals_miner_id_idx ON {{ .SchemaName | default "public"}}.miner_sector_deals_v2 USING hash (miner_id); | ||
CREATE INDEX IF NOT EXISTS miner_sector_deals_sector_id_idx ON {{ .SchemaName | default "public"}}.miner_sector_deals_v2 USING hash (sector_id); | ||
`, | ||
) | ||
} |