Skip to content

PHOENIX-6457 - Optionally store schema version string in SYSTEM.CATALOG - #1216

Merged
gjacoby126 merged 2 commits into
apache:4.xfrom
gjacoby126:PHOENIX-6457
May 6, 2021
Merged

PHOENIX-6457 - Optionally store schema version string in SYSTEM.CATALOG#1216
gjacoby126 merged 2 commits into
apache:4.xfrom
gjacoby126:PHOENIX-6457

Conversation

@gjacoby126

Copy link
Copy Markdown
Contributor

No description provided.

@stoty

Copy link
Copy Markdown
Contributor

💔 -1 overall

VoteSubsystemRuntimeComment
+0 🆗reexec5m 37sDocker mode activated.
_ Prechecks _
+1 💚dupname0m 0sNo case conflicting files found.
+1 💚hbaseanti0m 0sPatch does not have any anti-patterns.
+1 💚@author0m 0sThe patch does not contain any @author tags.
-1 ❌test4tests0m 0sThe patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.
_ 4.x Compile Tests _
+1 💚mvninstall15m 7s4.x passed
+1 💚compile1m 6s4.x passed
+1 💚checkstyle3m 12s4.x passed
+1 💚javadoc0m 49s4.x passed
+0 🆗spotbugs3m 17sphoenix-core in 4.x has 945 extant spotbugs warnings.
_ Patch Compile Tests _
+1 💚mvninstall6m 53sthe patch passed
+1 💚compile1m 6sthe patch passed
+1 💚cc1m 6sthe patch passed
+1 💚javac1m 6sthe patch passed
-1 ❌checkstyle3m 14sphoenix-core: The patch generated 76 new + 10260 unchanged - 25 fixed = 10336 total (was 10285)
+1 💚prototool0m 1sThere were no new prototool issues.
+1 💚whitespace0m 0sThe patch has no whitespace issues.
+1 💚javadoc0m 48sthe patch passed
-1 ❌spotbugs3m 30sphoenix-core generated 1 new + 944 unchanged - 1 fixed = 945 total (was 945)
_ Other Tests _
+1 💚unit195m 15sphoenix-core in the patch passed.
+1 💚asflicense0m 11sThe patch does not generate ASF License warnings.
241m 2s
ReasonTests
FindBugsmodule:phoenix-core
org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SCHEMA_VERSION_BYTES is a mutable array At MetaDataEndpointImpl.java: At MetaDataEndpointImpl.java:[line 344]
SubsystemReport/Notes
DockerClientAPI=1.41 ServerAPI=1.41 base: https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1216/1/artifact/yetus-general-check/output/Dockerfile
GITHUB PR#1216
Optional Testsdupname asflicense javac javadoc unit spotbugs hbaseanti checkstyle compile cc prototool
unameLinux e090cf77c106 4.15.0-128-generic #131-Ubuntu SMP Wed Dec 9 06:57:35 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Build toolmaven
Personalitydev/phoenix-personality.sh
git revision4.x / 282427d
Default JavaPrivate Build-1.8.0_242-8u242-b08-0ubuntu3~16.04-b08
checkstylehttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1216/1/artifact/yetus-general-check/output/diff-checkstyle-phoenix-core.txt
spotbugshttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1216/1/artifact/yetus-general-check/output/new-spotbugs-phoenix-core.html
Test Resultshttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1216/1/testReport/
Max. process+thread count5076 (vs. ulimit of 30000)
modulesC: phoenix-core U: phoenix-core
Console outputhttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1216/1/console
versionsgit=2.7.4 maven=3.3.9 spotbugs=4.1.3 prototool=1.10.0-dev
Powered byApache Yetus 0.12.0 https://yetus.apache.org

This message was automatically generated.

import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_DATA_TYPE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_STATEMENT;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_TYPE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.*;

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.

nit: unnecessary change.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Oops, thought I'd fixed all those before pushing. Fixed and repushed.

}

if (schemaVersion == null) {
tableUpsert.setNull(34, Types.VARCHAR);

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.

Or should have a default starting schema version?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'd considered it but decided against the idea because I didn't want to proscribe a particular versioning scheme...the idea is that a particular organization can choose their own version stamps (and that they don't have to if they don't want to, hence default null)

String alterViewSql = "ALTER VIEW " + viewFullName + " SET SCHEMA_VERSION='" + newVersion + "'";
conn.createStatement().execute(alterViewSql);
PTable view2 = PhoenixRuntime.getTableNoCache(conn, viewFullName);
assertEquals(newVersion, view2.getSchemaVersion());

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.

should we assert on changes on datatable schema version as well?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

There's not meant to be any cascade behavior here...what changes should I assert on? Just that that the base table didn't change? I could do that.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done.

throws Exception {
final String dataTableFullName = SchemaUtil.getTableName(schemaName, tableName);
String ddl =
"CREATE TABLE " + dataTableFullName + " (\n" + "ID1 VARCHAR(15) NOT NULL,\n"

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.

If there are any changes on the table schema like new column addition or drop of an existing column, how would the schema version be updated? I am thinking phoenix should increment the version or we need to enhance the alter DDL to include schema version also in the statement. If the former, schema version format should be fixed just like sequence number.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

It appears there's a rule in Phoenix grammar which prevents setting table level properties (like schema version) while adding a column, which means that when adding a column you'd need a separate ALTER TABLE SET SCHEMA_VERSION statement. Not ideal, but I was trying to avoid large changes in the plumbing.

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.

If I support changing Storage format or Column encoding, we will need to do alter table set schema again right? I think it will be good to invest in plumbing this change.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@gokceni - wouldn't those be table properties as well? Should be able to do in one statement.

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.

Good to have a follow-up Jira in that case. I feel ALTER ADD/DROP should implicitly increment the schema_version. If every org/customer decides the schema_version format by themselves, this will be difficult. WDYT?

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.

Agree with @swaroopak that we should do it.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I disagree that schema version should auto-increment. First, because an auto-incrementing int sequence already exists (see PTable.getSequenceNumber, which gets incremented by DDL statements), and second, because that's not really what this feature is meant to do.

The purpose of SCHEMA_VERSION is that it's a string which is relevant to a particular client application or applications and its release numbering.

Say application Foo has quarterly releases "Q1-2021", "Q1-2021.1", "Q2-2021", and so on. It creates tables A, B, and C as part of Q1-2021, makes a table property change to table B during Q1-2021.1, and then adds 2 more tables D and E and 1 column to an existing table C in Q2-2021.

At this point the schema versions are:
A: Q1-2021
B: Q1-2021.1
C: Q2-2021 (assuming there was a separate statement to update schema version after adding the column)
D: Q2-2021
E: Q2-2021

From this, the application Foo can check for each table that its schema version is the version that it expects (or not) and take action accordingly. An application running Q1-2021 can still interpret queries / messages against Table A, but might want to reject ones from tables B through E, because they're from newer schemas that it has no knowledge of.

@gjacoby126gjacoby126May 4, 2021

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

As @swaroopak points out, it's a pain to have to do the extra ALTER TABLE SET SCHEMA_VERSION statement after doing an add/drop column, so it would be nice if we could update this property as part of doing the add or drop column. I'll see if I can figure out the cause of why the existing restriction is there, and if it can be easily set aside.

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.

Thanks for the explanation. This makes sense

}

@Test
public void testCreateIndexSchemaVersion() throws Exception {

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.

How will the select statements behave? They need to be schema version aware at least implicitly.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Not sure I understand this point...

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.

Let's say I drop the column and schema version changes from v1 to v1.1. Currently, the phoenix will use v1.1 when processing a select * . can we add a test for that?

And is there a way I can query with old schema_version?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Phoenix won't really "use" a schema version at all during a select. To be precise, when it grabs the PTable to be able to interpret the query results, the schema version will be in the PTable, but it's not really used by the query logic.

The point of schema version is to allow:

  1. Applications to check to see if a table, view or index is compatible with a particular version of their schema
  2. In the future, when we have change streaming from Phoenix, messages will be annotated with the schema version so consumers of the message will be able to check to see if they can interpret the message (i.e, it's compatible with a particular version of a consuming application) or not.

throws Exception {
final String dataTableFullName = SchemaUtil.getTableName(schemaName, tableName);
String ddl =
"CREATE TABLE " + dataTableFullName + " (\n" + "ID1 VARCHAR(15) NOT NULL,\n"

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.

If I support changing Storage format or Column encoding, we will need to do alter table set schema again right? I think it will be good to invest in plumbing this change.

public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_15_0 = MIN_TABLE_TIMESTAMP + 29;
public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_16_0 = MIN_TABLE_TIMESTAMP + 33;
public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_17_0 = MIN_TABLE_TIMESTAMP + 34;
public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_17_0 = MIN_TABLE_TIMESTAMP + 35;

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.

How do we come up with 35?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Each syscat column needs an individual timestamp, and 33 was 4.16 + 1 for Physical table name, +1 for schema version

@stoty

stoty commented May 4, 2021

Copy link
Copy Markdown
Contributor

💔 -1 overall

VoteSubsystemRuntimeComment
+0 🆗reexec1m 11sDocker mode activated.
_ Prechecks _
+1 💚dupname0m 0sNo case conflicting files found.
+1 💚hbaseanti0m 0sPatch does not have any anti-patterns.
+1 💚@author0m 0sThe patch does not contain any @author tags.
-1 ❌test4tests0m 0sThe patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.
_ 4.x Compile Tests _
+1 💚mvninstall14m 51s4.x passed
+1 💚compile1m 5s4.x passed
+1 💚checkstyle3m 7s4.x passed
+1 💚javadoc0m 49s4.x passed
+0 🆗spotbugs3m 17sphoenix-core in 4.x has 945 extant spotbugs warnings.
_ Patch Compile Tests _
+1 💚mvninstall6m 46sthe patch passed
+1 💚compile1m 6sthe patch passed
+1 💚cc1m 6sthe patch passed
+1 💚javac1m 6sthe patch passed
-1 ❌checkstyle3m 15sphoenix-core: The patch generated 75 new + 10260 unchanged - 25 fixed = 10335 total (was 10285)
+1 💚prototool0m 1sThere were no new prototool issues.
+1 💚whitespace0m 0sThe patch has no whitespace issues.
+1 💚javadoc0m 46sthe patch passed
-1 ❌spotbugs3m 33sphoenix-core generated 1 new + 944 unchanged - 1 fixed = 945 total (was 945)
_ Other Tests _
+1 💚unit196m 41sphoenix-core in the patch passed.
+1 💚asflicense0m 9sThe patch does not generate ASF License warnings.
237m 33s
ReasonTests
FindBugsmodule:phoenix-core
org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SCHEMA_VERSION_BYTES is a mutable array At MetaDataEndpointImpl.java: At MetaDataEndpointImpl.java:[line 344]
SubsystemReport/Notes
DockerClientAPI=1.41 ServerAPI=1.41 base: https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1216/2/artifact/yetus-general-check/output/Dockerfile
GITHUB PR#1216
Optional Testsdupname asflicense javac javadoc unit spotbugs hbaseanti checkstyle compile cc prototool
unameLinux f793742f68bc 4.15.0-128-generic #131-Ubuntu SMP Wed Dec 9 06:57:35 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Build toolmaven
Personalitydev/phoenix-personality.sh
git revision4.x / 21bfbad
Default JavaPrivate Build-1.8.0_242-8u242-b08-0ubuntu3~16.04-b08
checkstylehttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1216/2/artifact/yetus-general-check/output/diff-checkstyle-phoenix-core.txt
spotbugshttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1216/2/artifact/yetus-general-check/output/new-spotbugs-phoenix-core.html
Test Resultshttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1216/2/testReport/
Max. process+thread count5093 (vs. ulimit of 30000)
modulesC: phoenix-core U: phoenix-core
Console outputhttps://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-1216/2/console
versionsgit=2.7.4 maven=3.3.9 spotbugs=4.1.3 prototool=1.10.0-dev
Powered byApache Yetus 0.12.0 https://yetus.apache.org

This message was automatically generated.

@swaroopakswaroopak left a comment

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.

Thank you for addressing the comments and answering questions. +1, LGTM

@gjacoby126
gjacoby126 merged commit ddc3996 into apache:4.xMay 6, 2021
swaroopak pushed a commit that referenced this pull request May 21, 2021
…OG (#1216)
* PHOENIX-6457 - Optionally store schema version string in SYSTEM.CATALOG
Sign up for freeto 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

@gjacoby126@stoty@swaroopak@gokceni