Skip to content

Commit 8f94e1d

Browse files
committed
remove indexing table, add defaults
1 parent a180b8c commit 8f94e1d

File tree

6 files changed

+112
-91
lines changed

6 files changed

+112
-91
lines changed

.circleci/config.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ jobs:
144144
description: Flags passed to go test.
145145
target:
146146
type: string
147-
default: "./..."
147+
default: "./... | grep -v itests"
148148
description: Import paths of packages to be tested.
149149
proofs-log-test:
150150
type: string
@@ -287,6 +287,5 @@ workflows:
287287
name: test-idxStore
288288
requires:
289289
- build
290-
suite: idxStore
291-
target: "./lib/indexing/indexstore/indexstore_test.go"
290+
suite: test-all
292291
get-params: true

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

Lines changed: 103 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
-- Table for Mk12 or Boost deals
22
CREATE TABLE market_mk12_deals (
33
uuid TEXT NOT NULL,
4-
<<<<<<< HEAD
54
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP AT TIME ZONE 'UTC',
6-
=======
75
sp_id BIGINT NOT NULL,
86

9-
created_at TIMESTAMPTZ NOT NULL DEFAULT TIMEZONE('UTC', NOW()),
10-
11-
>>>>>>> 48e953d (poller redesign)
127
signed_proposal_cid TEXT NOT NULL,
138
proposal_signature BYTEA NOT NULL,
149
proposal jsonb NOT NULL,
@@ -41,33 +36,13 @@ CREATE TABLE market_mk12_deals (
4136
unique (signed_proposal_cid)
4237
);
4338

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
46-
CREATE TABLE market_legacy_deals (
47-
signed_proposal_cid TEXT,
48-
proposal_signature BYTEA,
49-
proposal jsonb,
50-
piece_cid TEXT,
51-
piece_size BIGINT,
52-
offline BOOLEAN,
53-
verified BOOLEAN,
54-
sp_id BIGINT,
55-
start_epoch BIGINT,
56-
end_epoch BIGINT,
57-
publish_cid TEXT,
58-
fast_retrieval BOOLEAN,
59-
chain_deal_id BIGINT,
60-
created_at TIMESTAMPTZ,
61-
sector_num BIGINT,
62-
63-
primary key (sp_id, piece_cid, signed_proposal_cid)
64-
);
65-
6639
-- This table is used for storing piece metadata (piece indexing)
6740
CREATE TABLE market_piece_metadata (
6841
piece_cid TEXT NOT NULL PRIMARY KEY,
42+
6943
version INT NOT NULL DEFAULT 2,
7044
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP AT TIME ZONE 'UTC',
45+
7146
indexed BOOLEAN NOT NULL DEFAULT FALSE,
7247
indexed_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP AT TIME ZONE 'UTC',
7348

@@ -157,13 +132,9 @@ CREATE TABLE market_mk12_deal_pipeline (
157132
started BOOLEAN DEFAULT FALSE,
158133

159134
piece_cid TEXT NOT NULL,
160-
<<<<<<< HEAD
161135
piece_size BOOLEAN NOT NULL,
162-
=======
163-
piece_size BIGINT NOT NULL,
164-
file_size BIGINT DEFAULT NULL, -- raw piece size
136+
raw_size BIGINT DEFAULT NULL,
165137

166-
>>>>>>> 48e953d (poller redesign)
167138
offline BOOLEAN NOT NULL,
168139

169140
url TEXT DEFAULT NULL,
@@ -181,52 +152,94 @@ CREATE TABLE market_mk12_deal_pipeline (
181152
after_find_deal BOOLEAN DEFAULT FALSE,
182153

183154
sector BIGINT,
155+
reg_seal_proof INT NOT NULL,
184156
sector_offset BIGINT,
185157

186158
sealed BOOLEAN DEFAULT FALSE,
159+
160+
should_index BOOLEAN DEFAULT FALSE,
161+
indexing_created_at TIMESTAMPTZ,
162+
indexing_task_id BIGINT DEFAULT NULL,
187163
indexed BOOLEAN DEFAULT FALSE,
188164

165+
complete BOOLEAN NOT NULL DEFAULT FALSE,
166+
189167
constraint market_mk12_deal_pipeline_identity_key unique (uuid)
190168
);
191169

170+
-- This function creates indexing task based from move_storage tasks
171+
CREATE OR REPLACE FUNCTION create_indexing_task(task_id BIGINT, sealing_table TEXT)
172+
RETURNS VOID AS $$
173+
DECLARE
174+
query TEXT; -- Holds the dynamic SQL query
175+
pms RECORD; -- Holds each row returned by the query in the loop
176+
BEGIN
177+
-- Construct the dynamic SQL query based on the sealing_table
178+
IF sealing_table = 'sectors_sdr_pipeline' THEN
179+
query := format(
180+
'SELECT
181+
dp.uuid,
182+
ssp.reg_seal_proof
183+
FROM
184+
%I ssp
185+
JOIN
186+
market_mk12_deal_pipeline dp ON ssp.sp_id = dp.sp_id AND ssp.sector_num = dp.sector
187+
WHERE
188+
ssp.task_id_move_storage = $1', sealing_table);
189+
ELSIF sealing_table = 'sectors_snap_pipeline' THEN
190+
query := format(
191+
'SELECT
192+
dp.uuid,
193+
(SELECT reg_seal_proof FROM sectors_meta WHERE sp_id = ssp.sp_id AND sector_num = ssp.sector_num) AS reg_seal_proof
194+
FROM
195+
%I ssp
196+
JOIN
197+
market_mk12_deal_pipeline dp ON ssp.sp_id = dp.sp_id AND ssp.sector_num = dp.sector
198+
WHERE
199+
ssp.task_id_move_storage = $1', sealing_table);
200+
ELSE
201+
RAISE EXCEPTION 'Invalid sealing_table name: %', sealing_table;
202+
END IF;
203+
204+
-- Execute the dynamic SQL query with the task_id parameter
205+
FOR pms IN EXECUTE query USING task_id
206+
LOOP
207+
-- Update the market_mk12_deal_pipeline table with the reg_seal_proof and indexing_created_at values
208+
UPDATE market_mk12_deal_pipeline
209+
SET
210+
reg_seal_proof = pms.reg_seal_proof,
211+
indexing_created_at = NOW() AT TIME ZONE 'UTC'
212+
WHERE
213+
uuid = pms.uuid;
214+
END LOOP;
215+
216+
-- If everything is successful, simply exit
217+
RETURN;
218+
219+
EXCEPTION
220+
WHEN OTHERS THEN
221+
-- Rollback the transaction and raise the exception for Go to catch
222+
ROLLBACK;
223+
RAISE EXCEPTION 'Failed to create indexing task: %', SQLERRM;
224+
END;
225+
$$ LANGUAGE plpgsql;
226+
192227
-- This table can be used to track remote piece for offline deals
193228
-- The entries must be created by users
194229
CREATE TABLE market_offline_urls (
195-
piece_cid TEXT NOT NULL,
230+
uuid TEXT NOT NULL,
196231

197-
url TEXT NOT NULL,
198-
headers jsonb NOT NULL DEFAULT '{}',
232+
url TEXT NOT NULL,
233+
headers jsonb NOT NULL DEFAULT '{}',
199234

200-
raw_size BIGINT NOT NULL,
235+
raw_size BIGINT NOT NULL,
201236

202-
unique (piece_cid)
237+
CONSTRAINT market_offline_urls_uuid_fk FOREIGN KEY (uuid)
238+
REFERENCES market_mk12_deal_pipeline (uuid)
239+
ON DELETE CASCADE,
240+
CONSTRAINT market_offline_urls_uuid_unique UNIQUE (uuid)
203241
);
204242

205-
-- indexing tracker is separate from
206-
CREATE TABLE market_indexing_tasks (
207-
uuid TEXT NOT NULL,
208-
209-
sp_id BIGINT NOT NULL,
210-
sector_number BIGINT NOT NULL,
211-
reg_seal_proof INT NOT NULL,
212-
213-
piece_offset BIGINT NOT NULL,
214-
piece_size BIGINT NOT NULL,
215-
raw_size BIGINT NOT NULL,
216-
piece_cid TEXT NOT NULL,
217-
<<<<<<< HEAD
218-
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)
224-
task_id BIGINT DEFAULT NULL,
225-
226-
constraint market_indexing_tasks_identity_key
227-
unique (id, sp_id, sector_number, piece_offset, piece_size, piece_cid, reg_seal_proof)
228-
)
229-
230243
CREATE TABLE libp2p_keys (
231244
sp_id BIGINT NOT NULL,
232245
priv_key BYTEA NOT NULL,
@@ -255,33 +268,38 @@ CREATE TABLE direct_deals (
255268
keep_unsealed_copy BOOLEAN
256269
);
257270

271+
-- Add host column to allow local file based
272+
-- piece park
258273
ALTER TABLE parked_piece_refs
259274
ADD COLUMN host text;
260275

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-
);
276+
-- Table for old lotus market deals. This is just for deal
277+
-- which are still alive. It should not be used for any processing
278+
CREATE TABLE market_legacy_deals (
279+
signed_proposal_cid TEXT,
280+
sp_id BIGINT,
272281

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
282+
proposal_signature BYTEA,
283+
proposal jsonb,
284+
285+
piece_cid TEXT,
286+
piece_size BIGINT,
287+
288+
offline BOOLEAN,
289+
verified BOOLEAN,
290+
291+
start_epoch BIGINT,
292+
end_epoch BIGINT,
293+
294+
publish_cid TEXT,
295+
chain_deal_id BIGINT,
296+
297+
fast_retrieval BOOLEAN,
298+
299+
created_at TIMESTAMPTZ,
300+
sector_num BIGINT,
301+
302+
primary key (sp_id, piece_cid, signed_proposal_cid)
285303
);
286304

287305

market/storageingest/deal_ingest_seal.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"net/url"
1010
"time"
1111

12+
"github.com/filecoin-project/curio/build"
13+
"github.com/filecoin-project/curio/deps/config"
1214
logging "github.com/ipfs/go-log/v2"
1315
"golang.org/x/xerrors"
1416

market/storageingest/deal_ingest_snap.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"net/url"
1010
"time"
1111

12+
"github.com/filecoin-project/curio/build"
13+
"github.com/filecoin-project/curio/deps/config"
1214
"golang.org/x/xerrors"
1315

1416
"github.com/filecoin-project/go-address"

tasks/indexing/task_indexing.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ func (i *IndexingTask) Do(taskID harmonytask.TaskID, stillOwned func() bool) (do
102102
return false, xerrors.Errorf("checking if piece is already indexed: %w", err)
103103
}
104104

105-
// Return early if already indexed
106-
if indexed {
105+
// Return early if already indexed or should not be indexed
106+
if indexed || !task.ShouldIndex {
107107
err = i.recordCompletion(ctx, task, taskID, false)
108108
if err != nil {
109109
return false, err

tasks/storage-market/storage_market.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ func (d *CurioStorageDealMarket) findURLForOfflineDeals(ctx context.Context, dea
407407
if err != nil {
408408
return false, xerrors.Errorf("error making GET request: %w", err)
409409
}
410-
410+
411411
// Check the response code for 404
412412
if resp.StatusCode != http.StatusOK {
413413
if resp.StatusCode != 404 {

0 commit comments

Comments
 (0)