Skip to content

Commit a180b8c

Browse files
committed
poller redesign
1 parent 9ade420 commit a180b8c

File tree

18 files changed

+419
-363
lines changed

18 files changed

+419
-363
lines changed

.circleci/config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,10 @@ workflows:
283283
suite: test-all
284284
get-params: true
285285
resource_class: 2xlarge
286+
- test:
287+
name: test-idxStore
288+
requires:
289+
- build
290+
suite: idxStore
291+
target: "./lib/indexing/indexstore/indexstore_test.go"
292+
get-params: true

deps/config/doc_gen.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

documentation/en/configuration/default-curio-configuration.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,13 @@ description: The default curio configuration
493493
# type: []string
494494
#NoAnnounceAddresses = []
495495

496+
# SkipCommP can be used to skip doing a commP check before PublishDealMessage is sent on chain
497+
# Warning: If this check is skipped and there is a commP mismatch, all deals in the
498+
# sector will need to be sent again
499+
#
500+
# type: bool
501+
#SkipCommP = false
502+
496503

497504
[Ingest]
498505
# Maximum number of sectors that can be queued waiting for deals to start processing.

documentation/en/curio-cli/curio.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,15 @@ USAGE:
639639
curio market command [command options] [arguments...]
640640
641641
COMMANDS:
642+
<<<<<<< HEAD
642643
seal start sealing a deal sector early
643644
add-url Add URL to fetch data for offline deals
644645
help, h Shows a list of commands or help for one command
646+
=======
647+
seal start sealing a deal sector early
648+
import-data Import data for offline deal
649+
help, h Shows a list of commands or help for one command
650+
>>>>>>> 48e953d (poller redesign)
645651
646652
OPTIONS:
647653
--help, -h show help
@@ -661,6 +667,7 @@ OPTIONS:
661667
--help, -h show help
662668
```
663669

670+
<<<<<<< HEAD
664671
### curio market add-url
665672
```
666673
NAME:
@@ -674,6 +681,19 @@ OPTIONS:
674681
--header HEADER, -H HEADER [ --header HEADER, -H HEADER ] Custom HEADER to include in the HTTP request
675682
--url URL, -u URL URL to send the request to
676683
--help, -h show help
684+
=======
685+
### curio market import-data
686+
```
687+
NAME:
688+
curio market import-data - Import data for offline deal
689+
690+
USAGE:
691+
curio market import-data [command options] <deal UUID> <file> <host:port>
692+
693+
OPTIONS:
694+
--actor value Specify actor address to start sealing sectors for
695+
--help, -h show help
696+
>>>>>>> 48e953d (poller redesign)
677697
```
678698
679699
## curio fetch-params

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lV
191191
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
192192
github.com/crackcomm/go-gitignore v0.0.0-20231225121904-e25f5bc08668 h1:ZFUue+PNxmHlu7pYv+IYMtqlaO/0VwaGEqKepZf9JpA=
193193
github.com/crackcomm/go-gitignore v0.0.0-20231225121904-e25f5bc08668/go.mod h1:p1d6YEZWvFzEh4KLyvBcVSnrfNDDvK2zfK/4x2v/4pE=
194+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
194195
github.com/cskr/pubsub v1.0.2 h1:vlOzMhl6PFn60gRlTQQsIfVwaPB/B/8MziK8FhEPt/0=
195196
github.com/cskr/pubsub v1.0.2/go.mod h1:/8MzYXk/NJAz782G8RPkFzXTZVu63VotefPnR9TIRis=
196197
github.com/daaku/go.zipexe v1.0.2 h1:Zg55YLYTr7M9wjKn8SY/WcpuuEi+kR2u4E8RhvpyXmk=

harmony/harmonydb/sql/20240228-piece-park.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ create table parked_piece_refs (
3434
data_headers jsonb not null default '{}',
3535

3636
-- host Added in 202240730-market-migrations.sql
37+
<<<<<<< HEAD
3738
-- host text,
39+
=======
40+
host text,
41+
>>>>>>> 48e953d (poller redesign)
3842

3943
foreign key (piece_id) references parked_pieces(id) on delete cascade
4044
);

harmony/harmonydb/sql/20240730-market-migration.sql

Lines changed: 94 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,48 @@
1+
-- Table for Mk12 or Boost deals
12
CREATE TABLE market_mk12_deals (
23
uuid TEXT NOT NULL,
4+
<<<<<<< HEAD
35
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP AT TIME ZONE 'UTC',
6+
=======
7+
sp_id BIGINT NOT NULL,
8+
9+
created_at TIMESTAMPTZ NOT NULL DEFAULT TIMEZONE('UTC', NOW()),
10+
11+
>>>>>>> 48e953d (poller redesign)
412
signed_proposal_cid TEXT NOT NULL,
513
proposal_signature BYTEA NOT NULL,
614
proposal jsonb NOT NULL,
7-
piece_cid TEXT NOT NULL,
8-
piece_size BIGINT NOT NULL,
15+
916
offline BOOLEAN NOT NULL,
1017
verified BOOLEAN NOT NULL,
11-
sp_id BIGINT NOT NULL,
18+
1219
start_epoch BIGINT NOT NULL,
1320
end_epoch BIGINT NOT NULL,
21+
1422
client_peer_id TEXT NOT NULL,
23+
1524
chain_deal_id BIGINT DEFAULT NULL,
1625
publish_cid TEXT DEFAULT NULL,
26+
27+
piece_cid TEXT NOT NULL,
28+
piece_size BIGINT NOT NULL,
1729
length BIGINT DEFAULT NULL,
30+
1831
fast_retrieval BOOLEAN NOT NULL,
1932
announce_to_ipni BOOLEAN NOT NULL,
33+
2034
url TEXT DEFAULT NULL,
2135
url_headers jsonb NOT NULL DEFAULT '{}',
36+
2237
error TEXT DEFAULT NULL,
2338

2439
primary key (uuid, sp_id, piece_cid, signed_proposal_cid),
2540
unique (uuid),
2641
unique (signed_proposal_cid)
2742
);
2843

44+
-- Table for old lotus market deals. This is just for deal
45+
-- which are still alive. It should not be used for any processing
2946
CREATE TABLE market_legacy_deals (
3047
signed_proposal_cid TEXT,
3148
proposal_signature BYTEA,
@@ -46,6 +63,7 @@ CREATE TABLE market_legacy_deals (
4663
primary key (sp_id, piece_cid, signed_proposal_cid)
4764
);
4865

66+
-- This table is used for storing piece metadata (piece indexing)
4967
CREATE TABLE market_piece_metadata (
5068
piece_cid TEXT NOT NULL PRIMARY KEY,
5169
version INT NOT NULL DEFAULT 2,
@@ -57,14 +75,19 @@ CREATE TABLE market_piece_metadata (
5775
unique (piece_cid)
5876
);
5977

78+
-- This table binds the piece metadata to specific deals (piece indexing)
6079
CREATE TABLE market_piece_deal (
61-
id TEXT NOT NULL,
80+
id TEXT NOT NULL, -- (UUID for new deals, PropCID for old)
6281
piece_cid TEXT NOT NULL,
82+
6383
boost_deal BOOLEAN NOT NULL,
6484
legacy_deal BOOLEAN NOT NULL DEFAULT FALSE,
85+
6586
chain_deal_id BIGINT NOT NULL DEFAULT 0,
87+
6688
sp_id BIGINT NOT NULL,
6789
sector_num BIGINT NOT NULL,
90+
6891
piece_offset BIGINT NOT NULL,
6992
piece_length BIGINT NOT NULL,
7093
raw_size BIGINT NOT NULL,
@@ -74,6 +97,7 @@ CREATE TABLE market_piece_deal (
7497
unique (sp_id, id)
7598
);
7699

100+
-- This function is used to insert piece metadata and piece deal (piece indexing)
77101
CREATE OR REPLACE FUNCTION process_piece_deal(
78102
_id TEXT,
79103
_piece_cid TEXT,
@@ -108,64 +132,95 @@ VALUES (
108132
END;
109133
$$ LANGUAGE plpgsql;
110134

135+
-- Storage Ask for ask protocol
111136
CREATE TABLE market_mk12_storage_ask (
137+
sp_id BIGINT NOT NULL,
138+
112139
price BIGINT NOT NULL,
113140
verified_price BIGINT NOT NULL,
141+
114142
min_size BIGINT NOT NULL,
115143
max_size BIGINT NOT NULL,
116-
sp_id BIGINT NOT NULL,
144+
117145
created_at BIGINT NOT NULL,
118146
expiry BIGINT NOT NULL,
147+
119148
sequence BIGINT NOT NULL,
120149
unique (sp_id)
121150
);
122151

152+
-- Used for processing Mk12 deals
123153
CREATE TABLE market_mk12_deal_pipeline (
124154
uuid TEXT NOT NULL,
125155
sp_id BIGINT NOT NULL,
156+
126157
started BOOLEAN DEFAULT FALSE,
158+
127159
piece_cid TEXT NOT NULL,
160+
<<<<<<< HEAD
128161
piece_size BOOLEAN NOT NULL,
162+
=======
163+
piece_size BIGINT NOT NULL,
164+
file_size BIGINT DEFAULT NULL, -- raw piece size
165+
166+
>>>>>>> 48e953d (poller redesign)
129167
offline BOOLEAN NOT NULL,
130-
downloaded BOOLEAN DEFAULT FALSE,
168+
131169
url TEXT DEFAULT NULL,
132170
headers jsonb NOT NULL DEFAULT '{}',
133-
file_size BIGINT DEFAULT NULL,
171+
134172
commp_task_id BIGINT DEFAULT NULL,
135173
after_commp BOOLEAN DEFAULT FALSE,
136-
find_task_id BIGINT DEFAULT NULL,
137-
after_find BOOLEAN DEFAULT FALSE,
174+
138175
psd_task_id BIGINT DEFAULT NULL,
139176
after_psd BOOLEAN DEFAULT FALSE,
177+
140178
psd_wait_time TIMESTAMPTZ,
179+
141180
find_deal_task_id BIGINT DEFAULT NULL,
142181
after_find_deal BOOLEAN DEFAULT FALSE,
182+
143183
sector BIGINT,
144184
sector_offset BIGINT,
185+
145186
sealed BOOLEAN DEFAULT FALSE,
146187
indexed BOOLEAN DEFAULT FALSE,
147188

148189
constraint market_mk12_deal_pipeline_identity_key unique (uuid)
149190
);
150191

192+
-- This table can be used to track remote piece for offline deals
193+
-- The entries must be created by users
151194
CREATE TABLE market_offline_urls (
152195
piece_cid TEXT NOT NULL,
196+
153197
url TEXT NOT NULL,
154198
headers jsonb NOT NULL DEFAULT '{}',
199+
155200
raw_size BIGINT NOT NULL,
201+
156202
unique (piece_cid)
157203
);
158204

205+
-- indexing tracker is separate from
159206
CREATE TABLE market_indexing_tasks (
160-
id TEXT NOT NULL,
207+
uuid TEXT NOT NULL,
208+
161209
sp_id BIGINT NOT NULL,
162210
sector_number BIGINT NOT NULL,
163211
reg_seal_proof INT NOT NULL,
212+
164213
piece_offset BIGINT NOT NULL,
165214
piece_size BIGINT NOT NULL,
166215
raw_size BIGINT NOT NULL,
167216
piece_cid TEXT NOT NULL,
217+
<<<<<<< HEAD
168218
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP AT TIME ZONE 'UTC',
219+
=======
220+
221+
created_at TIMESTAMPTZ NOT NULL DEFAULT TIMEZONE('UTC', NOW()),
222+
223+
>>>>>>> 48e953d (poller redesign)
169224
task_id BIGINT DEFAULT NULL,
170225

171226
constraint market_indexing_tasks_identity_key
@@ -200,6 +255,35 @@ CREATE TABLE direct_deals (
200255
keep_unsealed_copy BOOLEAN
201256
);
202257

258+
ALTER TABLE parked_piece_refs
259+
ADD COLUMN host text;
260+
261+
create table file_parked_pieces (
262+
id bigserial primary key,
263+
created_at timestamp default current_timestamp,
264+
piece_cid text not null,
265+
piece_padded_size bigint not null,
266+
piece_raw_size bigint not null,
267+
complete boolean not null default false,
268+
task_id bigint default null,
269+
cleanup_task_id bigint default null,
270+
unique (piece_cid)
271+
);
272+
273+
/*
274+
* This table is used to keep track of the references to the file parked pieces
275+
* so that we can delete them when they are no longer needed.
276+
*
277+
* All references into the file_parked_pieces table should be done through this table.
278+
*/
279+
create table file_parked_piece_refs (
280+
ref_id bigserial primary key,
281+
piece_id bigint not null,
282+
data_url text not null,
283+
node text not null,
284+
foreign key (piece_id) references file_parked_pieces(id) on delete cascade
285+
);
286+
203287

204288

205289

lib/dealdata/urlpiecereader.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"io"
55
"net/http"
66
"net/url"
7+
"os"
78

89
"golang.org/x/xerrors"
910
)
@@ -62,8 +63,33 @@ func (u *UrlPieceReader) Read(p []byte) (n int, err error) {
6263
return 0, xerrors.Errorf("a non 200 response code: %s", resp.Status)
6364
}
6465

65-
// Set 'active' to the response body
66-
u.active = resp.Body
66+
if goUrl.Scheme == "file" {
67+
fileUrl := goUrl.Path
68+
file, err := os.Open(fileUrl)
69+
if err != nil {
70+
return 0, xerrors.Errorf("error opening file: %w", err)
71+
}
72+
u.active = file
73+
} else {
74+
req, err := http.NewRequest(http.MethodGet, u.Url, nil)
75+
if err != nil {
76+
return 0, xerrors.Errorf("error creating request: %w", err)
77+
}
78+
// Add custom headers for security and authentication
79+
req.Header = u.Headers
80+
// Create a client and make the request
81+
client := &http.Client{}
82+
resp, err := client.Do(req)
83+
if err != nil {
84+
return 0, xerrors.Errorf("error making GET request: %w", err)
85+
}
86+
if resp.StatusCode != 200 {
87+
return 0, xerrors.Errorf("a non 200 response code: %s", resp.Status)
88+
}
89+
90+
// Set 'active' to the response body
91+
u.active = resp.Body
92+
}
6793
}
6894

6995
// Calculate the maximum number of bytes we can read without exceeding RawSize

lib/indexing/indexstore/create.cql

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
CREATE TABLE IF NOT EXISTS PayloadToPiece (
2-
PieceCid BLOB,
2+
PieceCid BLOB, -- 20 bytes trimmed
33
PayloadMultihash BLOB,
44
BlockOffset BIGINT,
55
BlockSize BIGINT,
66
PRIMARY KEY (PayloadMultihash, PieceCid)
7-
);
8-
9-
CREATE INDEX piece_to_payload ON PayloadToPiece(PieceCid, PayloadMultihash);
7+
);

0 commit comments

Comments
 (0)