mirror of https://github.com/citusdata/citus.git
Clean up ErrorIfUnstableCreateOrAlterExtensionStmt
Swaps an Assert in for an ereport, and adds details and hints to the error message to help users with a possibly confusing scenario.pull/1277/head
parent
ad3fbd9689
commit
ef81b21a49
|
@ -135,6 +135,7 @@ static bool OptionsSpecifyOwnedBy(List *optionList, Oid *ownedByTableId);
|
||||||
static void ErrorIfDistributedRenameStmt(RenameStmt *renameStatement);
|
static void ErrorIfDistributedRenameStmt(RenameStmt *renameStatement);
|
||||||
|
|
||||||
/* Local functions forward declarations for helper functions */
|
/* Local functions forward declarations for helper functions */
|
||||||
|
static char * ExtractNewExtensionVersion(Node *parsetree);
|
||||||
static void CreateLocalTable(RangeVar *relation, char *nodeName, int32 nodePort);
|
static void CreateLocalTable(RangeVar *relation, char *nodeName, int32 nodePort);
|
||||||
static bool IsAlterTableRenameStmt(RenameStmt *renameStatement);
|
static bool IsAlterTableRenameStmt(RenameStmt *renameStatement);
|
||||||
static void ExecuteDistributedDDLJob(DDLJob *ddlJob);
|
static void ExecuteDistributedDDLJob(DDLJob *ddlJob);
|
||||||
|
@ -1341,23 +1342,53 @@ DeparseVacuumColumnNames(List *columnNameList)
|
||||||
static void
|
static void
|
||||||
ErrorIfUnstableCreateOrAlterExtensionStmt(Node *parsetree)
|
ErrorIfUnstableCreateOrAlterExtensionStmt(Node *parsetree)
|
||||||
{
|
{
|
||||||
|
char *newExtensionVersion = ExtractNewExtensionVersion(parsetree);
|
||||||
|
|
||||||
|
if (newExtensionVersion != NULL)
|
||||||
|
{
|
||||||
|
/* explicit version provided in CREATE or ALTER EXTENSION UPDATE; verify */
|
||||||
|
if (!MajorVersionsCompatible(newExtensionVersion, CITUS_EXTENSIONVERSION))
|
||||||
|
{
|
||||||
|
ereport(ERROR, (errmsg("specified version incompatible with loaded "
|
||||||
|
"Citus library"),
|
||||||
|
errdetail("Loaded library requires %s, but %s was specified.",
|
||||||
|
CITUS_MAJORVERSION, newExtensionVersion),
|
||||||
|
errhint("If a newer library is present, restart the database "
|
||||||
|
"and try the command again.")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* No version was specified, so PostgreSQL will use the default_version
|
||||||
|
* from the citus.control file. In case a new default is available, we
|
||||||
|
* will force a compatibility check of the latest available version.
|
||||||
|
*/
|
||||||
|
availableExtensionVersion = NULL;
|
||||||
|
ErrorIfAvailableVersionMismatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char *
|
||||||
|
ExtractNewExtensionVersion(Node *parsetree)
|
||||||
|
{
|
||||||
|
char *newVersion = NULL;
|
||||||
List *optionsList = NIL;
|
List *optionsList = NIL;
|
||||||
ListCell *optionsCell = NULL;
|
ListCell *optionsCell = NULL;
|
||||||
|
|
||||||
if (IsA(parsetree, CreateExtensionStmt))
|
if (IsA(parsetree, CreateExtensionStmt))
|
||||||
{
|
{
|
||||||
CreateExtensionStmt *createExtensionStmt = (CreateExtensionStmt *) parsetree;
|
optionsList = ((CreateExtensionStmt *) parsetree)->options;
|
||||||
optionsList = createExtensionStmt->options;
|
|
||||||
}
|
}
|
||||||
else if (IsA(parsetree, AlterExtensionStmt))
|
else if (IsA(parsetree, AlterExtensionStmt))
|
||||||
{
|
{
|
||||||
AlterExtensionStmt *alterExtensionStmt = (AlterExtensionStmt *) parsetree;
|
optionsList = ((AlterExtensionStmt *) parsetree)->options;
|
||||||
optionsList = alterExtensionStmt->options;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ereport(ERROR, (errmsg("unsupported node type, create or alter extension "
|
/* input must be one of the two above types */
|
||||||
"is expected")));
|
Assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(optionsCell, optionsList)
|
foreach(optionsCell, optionsList)
|
||||||
|
@ -1366,25 +1397,12 @@ ErrorIfUnstableCreateOrAlterExtensionStmt(Node *parsetree)
|
||||||
|
|
||||||
if (strcmp(defElement->defname, "new_version") == 0)
|
if (strcmp(defElement->defname, "new_version") == 0)
|
||||||
{
|
{
|
||||||
char *newVersion = strVal(defElement->arg);
|
newVersion = strVal(defElement->arg);
|
||||||
|
break;
|
||||||
if (!MajorVersionsCompatible(newVersion, CITUS_EXTENSIONVERSION))
|
|
||||||
{
|
|
||||||
ereport(ERROR, (errmsg("requested version is not compatible with "
|
|
||||||
"loaded Citus binaries.")));
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
return newVersion;
|
||||||
* new_version is not specified in ALTER EXTENSION statement, PostgreSQL will use
|
|
||||||
* default_version from citus.control file. We will flush availableExtensionVersion
|
|
||||||
* to re-check the available version from citus.control file.
|
|
||||||
*/
|
|
||||||
availableExtensionVersion = NULL;
|
|
||||||
ErrorIfAvailableVersionMismatch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,9 @@ WHERE pgd.refclassid = 'pg_extension'::regclass AND
|
||||||
DROP EXTENSION citus;
|
DROP EXTENSION citus;
|
||||||
\c
|
\c
|
||||||
CREATE EXTENSION citus VERSION '5.0';
|
CREATE EXTENSION citus VERSION '5.0';
|
||||||
ERROR: requested version is not compatible with loaded Citus binaries.
|
ERROR: specified version incompatible with loaded Citus library
|
||||||
|
DETAIL: Loaded library requires 6.2, but 5.0 was specified.
|
||||||
|
HINT: If a newer library is present, restart the database and try the command again.
|
||||||
-- re-create in newest version
|
-- re-create in newest version
|
||||||
\c
|
\c
|
||||||
CREATE EXTENSION citus;
|
CREATE EXTENSION citus;
|
||||||
|
|
Loading…
Reference in New Issue