Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for LionWeb 2024.1 #98

Merged
merged 37 commits into from
Jan 16, 2025
Merged

Add support for LionWeb 2024.1 #98

merged 37 commits into from
Jan 16, 2025

Conversation

joswarmer
Copy link
Contributor

@joswarmer joswarmer commented Dec 29, 2024

Changes in Version 0.3.0

  • Support for LionWeb 2024.1
  • Removed init request from dbAdmin
  • Request createRepository in dbAdmin has additional mandatory parameter lionWebVersion
    • All tests and applications need to add this parameter
    • The server config section for creating repositories also has this additional field
  • All requests fail if the LionWeb version of the chunk is not the same LionWeb version as the repository.

Copy link
Contributor

@dslmeinte dslmeinte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm reports several vulnerabilities that would need looking it, especially since this is a server component. (I know it's not the subject of this PR.)

packages/common/src/apiutil/functions.ts Outdated Show resolved Hide resolved
packages/bulkapi/src/database/LionWebQueries.ts Outdated Show resolved Hide resolved
packages/dbadmin/src/controllers/DBAdminApi.ts Outdated Show resolved Hide resolved
packages/dbadmin/src/tools/init-schema-without-history.ts Outdated Show resolved Hide resolved
packages/dbadmin/src/tools/init-schema-with-history.ts Outdated Show resolved Hide resolved
packages/dbadmin/src/tools/init-schema-without-history.ts Outdated Show resolved Hide resolved
@joswarmer joswarmer changed the title [WIP] Add lionweb version, make some strings (like table names) constants Add support for LionWeb 2024.1 Jan 6, 2025
@joswarmer
Copy link
Contributor Author

joswarmer commented Jan 6, 2025

npm reports several vulnerabilities that would need looking it, especially since this is a server component. (I know it's not the subject of this PR.)

Will take a look at them.

Now back to 0 vulnerablities.

import { getRepositoryData, validateLionWebVersion } from "@lionweb/repository-dbadmin"
import { getLanguageRegistry } from "@lionweb/repository-languages"
import { LionWebJsonChunk, LionWebValidator } from "@lionweb/validation"
// - unpack the request
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this at the right place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, moved to line 1 and rephrased.

@@ -2,15 +2,23 @@ import e, { Request, Response } from "express"
import {
getRepositoryParameter,
HttpSuccessCodes,
RepositoryData,
// RepositoryData,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, done

@@ -1,4 +1,5 @@
// functions implementing the LionWeb bulk API
import { getRepositoryData } from "@lionweb/repository-dbadmin"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

order of comments / imports correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reordered

let clientId = getStringParam(request, "clientId")
// TODO Change using new repository structure
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still open?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and fixed

@@ -23,6 +30,7 @@ describe("Repository tests", () => {
"./data/add-new-nodes/Disk-add-new-nodes-single-node.json",
"./data/Disk_A.json",
])
// await t.dbAdmin.deleteRepository("default")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@ftomassetti
Copy link
Contributor

ftomassetti commented Jan 10, 2025

@joswarmer
Today during the meeting you mention that we need to update the bulk import feature to the new support for multiple lionweb versions.

My understanding is that with this PR you add a column in the repositories table to record which lionweb version is used for a certain repository, but besides that the db schema does not change.

What the bulk import does is to skip the normal path for node insertions (which requires essentially calculating a diff with the current state) as we are dealing with a special situation: we are adding millions of nodes and they are all new, so we skip the diff, and we write directly to the DB, using the special COPY operation.

Now, given that the tables we are writing have not changed, my understanding is that these bulk import operations should still work and that we do not need to do anything (which is always ideal :D).

Does this make sense?

Edit: Maybe we just need to check all nodes are of the lionweb version we want too. We could do that as a preliminary check before starting the insertion, similarly as we do when checking that all sent nodes are new

Copy link
Contributor

@ftomassetti ftomassetti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added minor comments

configuration.md Outdated
"history": false
"history": false,
// Values can be: "2023.1" | "2024.1"
lionWebVersion: "2023.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 99% of users will go for the latest version, so I would use 2024.1 in this example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but that makes 2024.1 the default value from now on, as this document describes the default values.

get(key: KEY): VALUE[] {
const keyString = JSON.stringify(key)
let existingValue = this.map.get(keyString)
if (existingValue === undefined) {
existingValue = []
this.map.set(keyString, existingValue)
existingValue = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a weird indentation (3 spaces)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reformatted

@@ -98,7 +98,7 @@ export const nodesForQueryQuery = (nodesQuery: string): string => {
)
containments
FROM node_properties n1
LEFT JOIN ${CONTAINMENTS_TABLE} con ON con.node_id = n1.id
LEFT JOIN ${CONTAINMENTS_TABLE} con ON con.node_id = n1.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra white space at the end of the line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

configuration.md Outdated
@@ -36,7 +36,9 @@ Below is the server-config.json with all default values
// Values are "always" | "never" | "if-not-exists"
create: "if-not-exists"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
create: "if-not-exists"
"create": "if-not-exists",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added ""

@joswarmer
Copy link
Contributor Author

joswarmer commented Jan 13, 2025

@joswarmer Today during the meeting you mention that we need to update the bulk import feature to the new support for multiple lionweb versions.

My understanding is that with this PR you add a column in the repositories table to record which lionweb version is used for a certain repository, but besides that the db schema does not change.

That is correct.

What the bulk import does is to skip the normal path for node insertions (which requires essentially calculating a diff with the current state) as we are dealing with a special situation: we are adding millions of nodes and they are all new, so we skip the diff, and we write directly to the DB, using the special COPY operation.

Now, given that the tables we are writing have not changed, my understanding is that these bulk import operations should still work and that we do not need to do anything (which is always ideal :D).

Indeed, they should still work.

Does this make sense?

Edit: Maybe we just need to check all nodes are of the lionweb version we want too. We could do that as a preliminary check before starting the insertion, similarly as we do when checking that all sent nodes are new

I do not think it is possible to check a node for its LionWeb version, this information is not available. In a chunk of LionWeb nodes the only way to find the LionWeb version is the SerializationFormatVersion.

What want to avoid are scenarios like

  1. I am using 2024.1 and store nodes using the bulk import feature
  2. the repository is for 2023.1 nodes, but it cannot check the bulk import call and accepts the nodes
  3. I try to change nodes using the regular bulk API, using seralizationFormatVersion 2024.1 and cannot access my nodes because the repository refuses them.

One way of doing the check is to provide the LionWeb version as e.g. a parameter of the bulk import call, then this can be checked once (so it won't affect the performance). This way in step 1 I can state my expectation that the repo should support 2024.1

@@ -245,9 +261,8 @@ export function nodesToChunk(nodes: LionWebJsonNode[]): LionWebJsonChunk {
return {
serializationFormatVersion: "2023.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the serialization format should depend on the lionWebVersion of the repository

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, changes this (at several places)

@@ -245,9 +261,8 @@ export function nodesToChunk(nodes: LionWebJsonNode[]): LionWebJsonChunk {
return {
serializationFormatVersion: "2023.1",
languages: collectUsedLanguages(nodes),
nodes: nodes,
nodes: nodes
}
}

export const EMPTY_CHUNK = nodesToChunk([])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const EMPTY_CHUNK = nodesToChunk([])
export const EMPTY_CHUNKS: { [K in LionWebVersion]: LionWebJsonChunk } = {
"2023.1": nodesToChunk([], "2023.1"),
"2024.1": nodesToChunk([], "2024.1"),
};

I would suggest changing EMPTY_CHUNK into a map and update usages from EMPTY_CHUNK to EMPTY_CHUNKS[repositoryData.repository.lionweb_version]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done as suggested

configuration.md Outdated
"history": false
"history": false,
// Values can be: "2023.1" | "2024.1"
lionWebVersion: "2024.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lionWebVersion: "2024.1"
"lionWebVersion": "2024.1"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@joswarmer
Copy link
Contributor Author

npm reports several vulnerabilities that would need looking it, especially since this is a server component. (I know it's not the subject of this PR.)

Done, 0 left

@joswarmer joswarmer merged commit cbf8e0c into main Jan 16, 2025
2 checks passed
@joswarmer joswarmer deleted the lionweb-2024.1 branch January 16, 2025 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants