@@ -37,33 +37,14 @@ CREATE TABLE market_mk12_deals (
37
37
unique (signed_proposal_cid)
38
38
);
39
39
40
- -- Table for old lotus market deals. This is just for deal
41
- -- which are still alive. It should not be used for any processing
42
- CREATE TABLE market_legacy_deals (
43
- signed_proposal_cid TEXT ,
44
- proposal_signature BYTEA ,
45
- proposal jsonb,
46
- piece_cid TEXT ,
47
- piece_size BIGINT ,
48
- offline BOOLEAN ,
49
- verified BOOLEAN ,
50
- sp_id BIGINT ,
51
- start_epoch BIGINT ,
52
- end_epoch BIGINT ,
53
- publish_cid TEXT ,
54
- fast_retrieval BOOLEAN ,
55
- chain_deal_id BIGINT ,
56
- created_at TIMESTAMPTZ ,
57
- sector_num BIGINT ,
58
-
59
- primary key (sp_id, piece_cid, signed_proposal_cid)
60
- );
61
-
62
40
-- This table is used for storing piece metadata (piece indexing)
63
41
CREATE TABLE market_piece_metadata (
64
42
piece_cid TEXT NOT NULL PRIMARY KEY ,
65
- version INT NOT NULL DEFAULT 2 ,
43
+
44
+ version INT NOT NULL DEFAULT 2
45
+
66
46
created_at TIMESTAMPTZ NOT NULL DEFAULT TIMEZONE(' UTC' , NOW()),
47
+
67
48
indexed BOOLEAN NOT NULL DEFAULT FALSE,
68
49
indexed_at TIMESTAMPTZ NOT NULL DEFAULT TIMEZONE(' UTC' , NOW()),
69
50
@@ -103,21 +84,30 @@ CREATE OR REPLACE FUNCTION process_piece_deal(
103
84
_piece_offset BIGINT ,
104
85
_piece_length BIGINT ,
105
86
_raw_size BIGINT ,
87
+ _indexed BOOLEAN ,
106
88
_legacy_deal BOOLEAN DEFAULT FALSE,
107
89
_chain_deal_id BIGINT DEFAULT 0
108
90
)
109
91
RETURNS VOID AS $$
110
92
BEGIN
111
- INSERT INTO market_piece_metadata (piece_cid, indexed) VALUES (_piece_cid, TRUE)
112
- ON CONFLICT (piece_cid) DO UPDATE SET indexed = TRUE;
93
+ -- Insert or update the market_piece_metadata table
94
+ INSERT INTO market_piece_metadata (piece_cid, indexed)
95
+ VALUES (_piece_cid, _indexed)
96
+ ON CONFLICT (piece_cid) DO UPDATE SET
97
+ indexed = CASE
98
+ WHEN market_piece_metadata .indexed = FALSE THEN EXCLUDED .indexed
99
+ ELSE market_piece_metadata .indexed
100
+ END;
113
101
102
+ -- Insert into the market_piece_deal table
114
103
INSERT INTO market_piece_deal (
115
104
id, piece_cid, boost_deal, legacy_deal, chain_deal_id,
116
105
sp_id, sector_num, piece_offset, piece_length, raw_size
117
- ) VALUES (
118
- _id, _piece_cid, _boost_deal, _legacy_deal, _chain_deal_id,
119
- _sp_id, _sector_num, _piece_offset, _piece_length, _raw_size
120
- ) ON CONFLICT (sp_id, piece_cid, id) DO NOTHING;
106
+ ) VALUES (
107
+ _id, _piece_cid, _boost_deal, _legacy_deal, _chain_deal_id,
108
+ _sp_id, _sector_num, _piece_offset, _piece_length, _raw_size
109
+ ) ON CONFLICT (sp_id, piece_cid, id) DO NOTHING;
110
+
121
111
END;
122
112
$$ LANGUAGE plpgsql;
123
113
@@ -147,7 +137,7 @@ CREATE TABLE market_mk12_deal_pipeline (
147
137
148
138
piece_cid TEXT NOT NULL ,
149
139
piece_size BIGINT NOT NULL ,
150
- file_size BIGINT DEFAULT NULL , -- raw piece size
140
+ raw_size BIGINT DEFAULT NULL ,
151
141
152
142
offline BOOLEAN NOT NULL ,
153
143
@@ -166,14 +156,78 @@ CREATE TABLE market_mk12_deal_pipeline (
166
156
after_find_deal BOOLEAN DEFAULT FALSE,
167
157
168
158
sector BIGINT ,
159
+ reg_seal_proof INT NOT NULL ,
169
160
sector_offset BIGINT ,
170
161
171
162
sealed BOOLEAN DEFAULT FALSE,
163
+
164
+ should_index BOOLEAN DEFAULT FALSE,
165
+ indexing_created_at TIMESTAMPTZ ,
166
+ indexing_task_id BIGINT DEFAULT NULL ,
172
167
indexed BOOLEAN DEFAULT FALSE,
173
168
169
+ complete BOOLEAN NOT NULL DEFAULT FALSE,
170
+
174
171
constraint market_mk12_deal_pipeline_identity_key unique (uuid)
175
172
);
176
173
174
+ -- This function creates indexing task based from move_storage tasks
175
+ CREATE OR REPLACE FUNCTION create_indexing_task (task_id BIGINT , sealing_table TEXT )
176
+ RETURNS VOID AS $$
177
+ DECLARE
178
+ query TEXT ; -- Holds the dynamic SQL query
179
+ pms RECORD; -- Holds each row returned by the query in the loop
180
+ BEGIN
181
+ -- Construct the dynamic SQL query based on the sealing_table
182
+ IF sealing_table = ' sectors_sdr_pipeline' THEN
183
+ query := format(
184
+ ' SELECT
185
+ dp.uuid,
186
+ ssp.reg_seal_proof
187
+ FROM
188
+ %I ssp
189
+ JOIN
190
+ market_mk12_deal_pipeline dp ON ssp.sp_id = dp.sp_id AND ssp.sector_num = dp.sector
191
+ WHERE
192
+ ssp.task_id_move_storage = $1' , sealing_table);
193
+ ELSIF sealing_table = ' sectors_snap_pipeline' THEN
194
+ query := format(
195
+ ' SELECT
196
+ dp.uuid,
197
+ (SELECT reg_seal_proof FROM sectors_meta WHERE sp_id = ssp.sp_id AND sector_num = ssp.sector_num) AS reg_seal_proof
198
+ FROM
199
+ %I ssp
200
+ JOIN
201
+ market_mk12_deal_pipeline dp ON ssp.sp_id = dp.sp_id AND ssp.sector_num = dp.sector
202
+ WHERE
203
+ ssp.task_id_move_storage = $1' , sealing_table);
204
+ ELSE
205
+ RAISE EXCEPTION ' Invalid sealing_table name: %' , sealing_table;
206
+ END IF;
207
+
208
+ -- Execute the dynamic SQL query with the task_id parameter
209
+ FOR pms IN EXECUTE query USING task_id
210
+ LOOP
211
+ -- Update the market_mk12_deal_pipeline table with the reg_seal_proof and indexing_created_at values
212
+ UPDATE market_mk12_deal_pipeline
213
+ SET
214
+ reg_seal_proof = pms .reg_seal_proof ,
215
+ indexing_created_at = NOW() AT TIME ZONE ' UTC'
216
+ WHERE
217
+ uuid = pms .uuid ;
218
+ END LOOP;
219
+
220
+ -- If everything is successful, simply exit
221
+ RETURN;
222
+
223
+ EXCEPTION
224
+ WHEN OTHERS THEN
225
+ -- Rollback the transaction and raise the exception for Go to catch
226
+ ROLLBACK ;
227
+ RAISE EXCEPTION ' Failed to create indexing task: %' , SQLERRM;
228
+ END;
229
+ $$ LANGUAGE plpgsql;
230
+
177
231
-- This table can be used to track remote piece for offline deals
178
232
-- The entries must be created by users
179
233
CREATE TABLE market_offline_urls (
@@ -187,27 +241,6 @@ CREATE TABLE market_offline_urls (
187
241
unique (piece_cid)
188
242
);
189
243
190
- -- indexing tracker is separate from
191
- CREATE TABLE market_indexing_tasks (
192
- uuid TEXT NOT NULL ,
193
-
194
- sp_id BIGINT NOT NULL ,
195
- sector_number BIGINT NOT NULL ,
196
- reg_seal_proof INT NOT NULL ,
197
-
198
- piece_offset BIGINT NOT NULL ,
199
- piece_size BIGINT NOT NULL ,
200
- raw_size BIGINT NOT NULL ,
201
- piece_cid TEXT NOT NULL ,
202
-
203
- created_at TIMESTAMPTZ NOT NULL DEFAULT TIMEZONE(' UTC' , NOW()),
204
-
205
- task_id BIGINT DEFAULT NULL ,
206
-
207
- constraint market_indexing_tasks_identity_key
208
- unique (id, sp_id, sector_number, piece_offset, piece_size, piece_cid, reg_seal_proof)
209
- );
210
-
211
244
CREATE TABLE libp2p_keys (
212
245
sp_id BIGINT NOT NULL ,
213
246
priv_key BYTEA NOT NULL ,
@@ -216,33 +249,38 @@ CREATE TABLE libp2p_keys (
216
249
no_announce_address TEXT NOT NULL
217
250
);
218
251
252
+ -- Add host column to allow local file based
253
+ -- piece park
219
254
ALTER TABLE parked_piece_refs
220
255
ADD COLUMN host text ;
221
256
222
- create table file_parked_pieces (
223
- id bigserial primary key ,
224
- created_at timestamp default current_timestamp ,
225
- piece_cid text not null ,
226
- piece_padded_size bigint not null ,
227
- piece_raw_size bigint not null ,
228
- complete boolean not null default false,
229
- task_id bigint default null ,
230
- cleanup_task_id bigint default null ,
231
- unique (piece_cid)
232
- );
257
+ -- Table for old lotus market deals. This is just for deal
258
+ -- which are still alive. It should not be used for any processing
259
+ CREATE TABLE market_legacy_deals (
260
+ signed_proposal_cid TEXT ,
261
+ sp_id BIGINT ,
233
262
234
- /*
235
- * This table is used to keep track of the references to the file parked pieces
236
- * so that we can delete them when they are no longer needed.
237
- *
238
- * All references into the file_parked_pieces table should be done through this table.
239
- */
240
- create table file_parked_piece_refs (
241
- ref_id bigserial primary key ,
242
- piece_id bigint not null ,
243
- data_url text not null ,
244
- node text not null ,
245
- foreign key (piece_id) references file_parked_pieces(id) on delete cascade
263
+ proposal_signature BYTEA ,
264
+ proposal jsonb,
265
+
266
+ piece_cid TEXT ,
267
+ piece_size BIGINT ,
268
+
269
+ offline BOOLEAN ,
270
+ verified BOOLEAN ,
271
+
272
+ start_epoch BIGINT ,
273
+ end_epoch BIGINT ,
274
+
275
+ publish_cid TEXT ,
276
+ chain_deal_id BIGINT ,
277
+
278
+ fast_retrieval BOOLEAN ,
279
+
280
+ created_at TIMESTAMPTZ ,
281
+ sector_num BIGINT ,
282
+
283
+ primary key (sp_id, piece_cid, signed_proposal_cid)
246
284
);
247
285
248
286
0 commit comments