Skip to content

Update extension version checking logic#325

Merged
var77 merged 4 commits intomainfrom
varik/strict-version-checking
Aug 7, 2024
Merged

Update extension version checking logic#325
var77 merged 4 commits intomainfrom
varik/strict-version-checking

Conversation

@var77
Copy link
Copy Markdown
Collaborator

@var77 var77 commented Jul 24, 2024

Generate static array from CMake for compatible version list based on update file names. Use that array to check if current catalog version of extension is compatible with current binary version

@var77 var77 requested a review from Ngalstyan4 July 24, 2024 08:58
Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

The pull request updates the extension version checking logic to ensure compatibility between binary and SQL versions, adding new helper functions for semantic version comparison.

  • sql/lantern.sql: Introduced _lantern_internal functions for version checking and comparison.
  • src/hnsw.c: Added lantern_internal_get_binary_version function for retrieving binary version.
  • src/hnsw/build.c: Replaced VersionsMatch() with CmpExtensionVersions() for stricter version checks.
  • src/hnsw/utils.c: Renamed and updated VersionsMatch to CmpExtensionVersions with enhanced logic.
  • test/expected/ext_relocation.out: Added tests for new internal version checking functions.

10 file(s) reviewed, 18 comment(s)
Edit PR Review Bot Settings

sql/lantern.sql Outdated
Comment on lines +927 to +928
CREATE FUNCTION _lantern_internal.get_binary_version() RETURNS TEXT
AS 'MODULE_PATHNAME', 'lantern_internal_get_binary_version' LANGUAGE C STABLE STRICT PARALLEL SAFE;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Info: Added function to get the binary version of the Lantern extension.

sql/lantern.sql Outdated
Comment on lines +930 to +937
CREATE OR REPLACE FUNCTION _lantern_internal.get_catalog_version() RETURNS TEXT as $$
DECLARE
cat_version TEXT;
BEGIN
SELECT extversion INTO cat_version FROM pg_extension WHERE extname = 'lantern';
RETURN cat_version;
END;
$$ LANGUAGE plpgsql;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Info: Added function to get the catalog version of the Lantern extension.

sql/lantern.sql Outdated
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION _lantern_internal.parse_semver(semver text)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Info: Added function to parse semantic versioning (semver) strings.

sql/lantern.sql Outdated
-- 0 if versions are matching
-- 1 if binary version is bigger than catalog version
-- -1 if binary version is smaller than catalog version
CREATE OR REPLACE FUNCTION _lantern_internal.compare_extension_versions(catalog_version TEXT, binary_version TEXT) RETURNS INT as $$
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Info: Added function to compare the binary and catalog versions of the Lantern extension.

#include <utils/selfuncs.h>
#include <utils/spccache.h>

#include "version.h"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Info: Included version.h to access version information.

src/hnsw/utils.h Outdated
void label2ItemPointer(usearch_label_t label, ItemPointer itemPtr);
float4 *ToFloat4Array(ArrayType *arr, int *dim_out);
bool VersionsMatch();
int CmpExtensionVersions();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Info: Renamed VersionsMatch to CmpExtensionVersions to implement stricter version checking.

extschema | proname | proschema
-----------+--------------------------------+-------------------
schema1 | _create_ldb_operator_classes | _lantern_internal
schema1 | compare_extension_versions | _lantern_internal
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Info: Added compare_extension_versions function to compare extension versions.

schema1 | create_pq_codebook | _lantern_internal
schema1 | failure_point_enable | _lantern_internal
schema1 | forbid_table_change | _lantern_internal
schema1 | get_binary_version | _lantern_internal
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Info: Added get_binary_version function to retrieve the binary version of the extension.

schema1 | failure_point_enable | _lantern_internal
schema1 | forbid_table_change | _lantern_internal
schema1 | get_binary_version | _lantern_internal
schema1 | get_catalog_version | _lantern_internal
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Info: Added get_catalog_version function to retrieve the catalog version of the extension.

schema1 | get_catalog_version | _lantern_internal
schema1 | mask_arrays | _lantern_internal
schema1 | mask_order_by_in_plan | _lantern_internal
schema1 | parse_semver | _lantern_internal
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Info: Added parse_semver function to parse semantic version strings.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 24, 2024

Benchmarks

metric old new pct change
recall (after create) 0.951 0.955 +0.42%
recall (after insert) 0.000 0.000 -
select tps 25374.002 25470.947 +0.38%
select bulk(100) tps 35.720 35.393 -0.92%
select latency (ms) 0.745 ± 1.560𝜎 0.704 ± 1.548𝜎 -5.50%
select bulk(100) latency (ms) 885.606 ± 99.034𝜎 870.792 ± 131.370𝜎 -1.67%
create latency (ms) 396793.805 400092.278 +0.83%
insert tps 431.859 445.026 +3.05%
insert bulk(100) tps 4.802 4.645 -3.27%
insert latency (ms) 73.505 ± 15.007𝜎 71.161 ± 15.660𝜎 -3.19%
insert bulk(100) latency (ms) 6513.105 ± 135.856𝜎 6780.624 ± 88.691𝜎 +4.11%
disk usage (bytes) 8192008192.000 8192008192.000 -

@var77 var77 force-pushed the varik/strict-version-checking branch from b43ace5 to 5474e79 Compare July 24, 2024 14:52
…nd use it to check for incompatible sql and binary versions
@var77 var77 force-pushed the varik/strict-version-checking branch from 5474e79 to fcfb4d9 Compare July 25, 2024 12:49
@codecov
Copy link
Copy Markdown

codecov bot commented Jul 25, 2024

Codecov Report

Attention: Patch coverage is 41.66667% with 21 lines in your changes missing coverage. Please review.

Files Patch % Lines
src/hnsw/utils.c 34.37% 15 Missing and 6 partials ⚠️

📢 Thoughts on this report? Let us know!

@var77 var77 force-pushed the varik/strict-version-checking branch 3 times, most recently from bb8f4fe to 126cc3f Compare July 26, 2024 06:06
@var77 var77 force-pushed the varik/strict-version-checking branch from 126cc3f to 0f8608f Compare July 30, 2024 08:17
src/hnsw/utils.c Outdated
version_text = DatumGetTextP(val);
catalog_version = text_to_cstring(version_text);

if(strlen(catalog_version) == 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so, if catalog version has zero length, we assume it is always compatible with any binary version?
is it what we want? I would think we would consider this error in all cases.

src/hnsw/utils.c Outdated

// Grab the result and check that it matches the version in the generated header
version_text = DatumGetTextP(val);
catalog_version = text_to_cstring(version_text);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You are storing version_text in a global variable but I am pretty sure it gets free()ed after the current context is gone, while catalog_version remains available as a freed pointer in the global process scope.

Is catalog_version actually used anywhere/
if so, it should probably be a NAME-sized static array into which you can strncpy the value of version_text

src/hnsw/utils.c Outdated
bool versions_match = false;
bool version_checked = false;
bool version_checked = false;
bool versions_match = true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why default versions_match to true here?

…ion string using strncopy instead of using pointer
@var77 var77 merged commit 39d6fac into main Aug 7, 2024
@var77 var77 deleted the varik/strict-version-checking branch August 7, 2024 08:48
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.

2 participants