Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Duniter Datapod
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
Duniter Datapod
Commits
aa7afc85
Commit
aa7afc85
authored
Apr 9, 2024
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
refac to prepare database injestion
parent
693f66a4
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+9
-1
9 additions, 1 deletion
README.md
src/indexer/handlers.ts
+8
-0
8 additions, 0 deletions
src/indexer/handlers.ts
src/indexer/types.ts
+9
-0
9 additions, 0 deletions
src/indexer/types.ts
src/scripts/start-indexer.ts
+71
-38
71 additions, 38 deletions
src/scripts/start-indexer.ts
with
97 additions
and
39 deletions
README.md
+
9
−
1
View file @
aa7afc85
...
...
@@ -4,7 +4,7 @@
```
sh
pnpm
install
pnpm dev
pnpm dev
# for vue dev UI
```
## Import Cesium+ data
...
...
@@ -32,6 +32,14 @@ time npx tsx src/scripts/cesium-plus-import.ts
# bafyreigczogsiuhaqus7eucalkwsy4vfkh3f4zg3c3rkvltxrwji6p5rnq
```
## Start collector and indexer
To start pubsub collector to IPFS and database indexer
```
sh
npx tsx src/scripts/start-indexer.ts
```
## TODO
When using Kubo node, libp2p is not needed at all.
This diff is collapsed.
Click to expand it.
src/indexer/handlers.ts
0 → 100644
+
8
−
0
View file @
aa7afc85
import
type
{
DiffData
}
from
'
./types
'
import
{
CID
}
from
'
multiformats
'
// diff indexer event handler
export
async
function
indexDiff
(
diff
:
DiffData
)
{}
// start indexer event handler
export
async
function
indexStart
(
cid
:
CID
)
{}
This diff is collapsed.
Click to expand it.
src/indexer/types.ts
0 → 100644
+
9
−
0
View file @
aa7afc85
import
{
CID
}
from
'
multiformats
'
import
type
{
IndexRequest
}
from
'
../types
'
// data added between two CIDs
export
interface
DiffData
{
oldCID
:
CID
newCID
:
CID
newItems
:
Array
<
[
CID
,
IndexRequest
]
>
}
This diff is collapsed.
Click to expand it.
src/scripts/start-indexer.ts
+
71
−
38
View file @
aa7afc85
...
...
@@ -6,17 +6,17 @@ import type { IndexRequest } from '../types'
import
{
IPNS
,
EMPTY_NODE_CID
}
from
'
../consts
'
import
{
CID
}
from
'
multiformats
'
import
EventEmitter
from
'
events
'
import
{
indexDiff
,
indexStart
}
from
'
../indexer/handlers
'
// this script allows to start an indexer
// === GLOBALS ===
// queue of index requests waiting to be processed
const
processQueue
:
Array
<
[
CID
,
IndexRequest
]
>
=
[]
const
queueE
vents
=
new
EventEmitter
()
const
e
vents
=
new
EventEmitter
()
let
isProcessingQueue
=
false
// show args
// console.log(process.argv)
/// global rootCID variable
// initialize it:
// - from CID if given
...
...
@@ -25,8 +25,23 @@ let isProcessingQueue = false
// - as empty node else
let
rootCID
=
EMPTY_NODE_CID
// === EVENTS ===
// event type
enum
evtype
{
// event to trigger collecting new index requests in queue
trigger
=
'
trigger
'
,
// event to trigger injestion of new requests in database
indexDiff
=
'
indexThat
'
,
// event to trigger database sync from scratch or last state
indexStart
=
'
start
'
}
// === INIT ===
// get root cid from arg if given
if
(
process
.
argv
.
length
>=
3
)
{
async
function
setRootCIDfromArgs
(
argv
:
string
[])
{
if
(
argv
.
length
>=
3
)
{
const
arg
=
process
.
argv
[
2
]
try
{
// try parse as CID
...
...
@@ -59,10 +74,11 @@ if (process.argv.length >= 3) {
console
.
log
(
'
using empty node insead
'
)
}
}
}
// ===
define what to do of pubsub messages and start listening
===
// ===
HANDLERS
===
// message handler
//
pubsub
message handler
function
handleMessage
(
message
:
any
)
{
// console.log('received message')
// console.log(message)
...
...
@@ -90,7 +106,7 @@ function handleMessage(message: any) {
// low trust => sandboxed HAMT
processQueue
.
push
([
cid
,
dag
])
queueE
vents
.
emit
(
'
trigger
'
)
e
vents
.
emit
(
evtype
.
trigger
)
// this is all that this indexer does
// the rest (autopinning, postgres indexing... will be managed by an other part of the indexer)
...
...
@@ -108,11 +124,11 @@ function handleBatch() {
// ignore event if already processing something or if queue is empty
if
(
isProcessingQueue
)
return
if
(
processQueue
.
length
==
0
)
return
// if not processing do process
// if not processing
,
do process
isProcessingQueue
=
true
// take elements from queue
let
i
=
undefined
const
items
=
[]
const
items
:
Array
<
[
CID
,
IndexRequest
]
>
=
[]
while
((
i
=
processQueue
.
shift
())
!=
undefined
)
{
items
.
push
(
i
)
}
...
...
@@ -126,22 +142,39 @@ function handleBatch() {
.
then
((
v
)
=>
mergeInodesSync
(
v
.
value
,
tree
))
.
then
((
cid
)
=>
{
// update CID and schedule publishing of new CID in history
const
oldCID
=
rootCID
rootCID
=
cid
console
.
log
(
`new root CID
${
cid
}
`
)
kubo
.
name
.
publish
(
rootCID
,
{
ttl
:
'
1s
'
})
publishHistory
(
rootCID
)
isProcessingQueue
=
false
queueEvents
.
emit
(
'
trigger
'
)
// trigger an other event in case new requests arrived meanwhile
events
.
emit
(
evtype
.
trigger
)
// emit event to be processed by indexer
events
.
emit
(
evtype
.
indexDiff
,
{
oldCID
:
oldCID
,
newCID
:
rootCID
,
newItems
:
items
})
})
}
queueEvents
.
on
(
'
trigger
'
,
handleBatch
)
queueEvents
.
on
(
'
trigger
'
,
handleBatch
)
// ===================== START ===========================
// console.log(await kubo.pubsub.ls())
// console.log(await kubo.pubsub.peers(TOPIC))
// set root CID from CLI args
await
setRootCIDfromArgs
(
process
.
argv
)
// bind event handlers
events
.
on
(
evtype
.
trigger
,
handleBatch
)
events
.
on
(
evtype
.
indexDiff
,
indexDiff
)
events
.
on
(
evtype
.
indexStart
,
indexStart
)
kubo
.
pubsub
.
subscribe
(
TOPIC
,
handleMessage
)
// emit event to tell indexer to start indexing to database
// if it is starting from scratch, it will iterate over all values
// if it already indexed up to a given cid, it will only iterate over the diff
events
.
emit
(
evtype
.
indexStart
,
rootCID
)
// // optionally publish new cid and history with
// kubo.name.publish(rootCID, { ttl: '1s' })
// publishHistory(rootCID)
// process loop
console
.
log
(
'
listening...
'
)
setInterval
(()
=>
{},
1
<<
30
)
;[
'
SIGINT
'
,
'
SIGTERM
'
,
'
SIGQUIT
'
].
forEach
((
signal
)
=>
process
.
on
(
signal
,
process
.
exit
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment