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

Feature issue#49 #76

Merged
merged 9 commits into from Feb 27, 2015
Merged

Feature issue#49 #76

merged 9 commits into from Feb 27, 2015

Conversation

onderkalaci
Copy link
Member

This pull request includes commits which add dependency control for pg_shard extension and distributed tables.

Fixes #49

Code Review Tasks

  • Rebase this branch onto develop (i.e. git fetch; git rebase -i origin/develop) or merge develop into this branch
  • Remove DROP TABLE logic and all functions/tests used by that logic
  • Tell me what happens when you run DROP EXTENSION pg_shard against a database where pg_shard isn't yet created (i.e. does your block run, or is it skipped?)
  • Don't do if (booleanVar == true), just do if (booleanVar)
  • Always use the bounded version of string/memory functions (strncmp, never strcmp)
  • Pull up DistributedTablesExist so it's not called in a loop
  • Don't check a condition just to set a boolean flag to true in an if block. Just set the boolean flag to the condition's value

@@ -2007,6 +2008,107 @@ PgShardProcessUtility(Node *parsetree, const char *queryString,
}
}
}
else if (statementType == T_DropStmt)
{
DropStmt *dropStatement = (DropStmt *) parsetree;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The nesting gets pretty deep here. Can you move the drop logic into its own function?

@jasonmp85
Copy link
Collaborator

Left some comments, mostly minor for now. Still want to think overnight about this approach, as it's quite a bit of code for something that's conceptually pretty simple. Will add more comments tomorrow morning.

@onderkalaci
Copy link
Member Author

@jasonmp85 Well, in the beginning of our discussions, we thought that we should write C codes for this purpose. If we are going to implement it with C (either event trigger or utility hook), we need to write these codes (at least I couldn't find any other way).

So, we may consider writing a SQL event trigger.

Or, I am not sure, but if we use referential integrity constraints during metadata table creation, would the code become smaller? For instance, deleting a row from partition column propagates to shard and shard_placements.

I haven't addressed your feedback, I think it is better to decide high level design first.

@onderkalaci
Copy link
Member Author

@jasonmp85 we have chatted with @sumedhpathak and thought that we could divide the issue into two. One is for DROP EXTENSION and the other is DROP TABLE. In this way, we can merge DROP EXTENSION for v1.1, which is simpler and requires small code changes.
So, you can also consider this option for the issue.

@jasonmp85
Copy link
Collaborator

OK, the more I think about it, the more I think @sumedhpathak and you are on to something with the "let's split this in two" idea…

  • The foreign key concept might have some merit and was precisely what I was thinking when considering whether this could be done with a higher level (less LoC) implementation
  • Prevent deletion of metadata when still in use #49 really only discusses removing the extension, anyhow
  • Much of the code here is boilerplate stuff to remove rows. If we just address the extension dropping, that goes away

@onderkalaci Can you rework this to just handle dropping the extension and we'll open an issue for later about dropping tables?

@jasonmp85
Copy link
Collaborator

OK, I left all my feedback. Can you remove the DROP TABLE logic and address feedback? Adding my checklist…

static void
PgShardProcessUtilityDropCommands(Node *parsetree)
{
DropStmt *dropStatement = (DropStmt *) parsetree;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the idiom within PostgreSQL is to cast this before calling the function so the function signature can be more specific.

onderkalaci and others added 9 commits February 26, 2015 18:03
This commit aims to test feasibility of using utility hook for
controlling DROP EXTENSION statement.
This commits applies some style refactoring.
This commits add a dependency control for distributed tables. If a table
is dropped with CASCADE, delete all the dependent metadata information.
Else, do not allow to drop the table.
This commit aims to add some tests for pg_shard dependency for both
distributed tables and the extension itself.
This commit applies some style changes.
This commit aims to remove process utility hook codes that controls the
dependency on distributed tables. Also, this commit addresses some of
the minor style changes.
This commit updates some of the comments in the code.
This commit updated some of the comments.
@jasonmp85
Copy link
Collaborator

@onderkalaci I hope this isn't too presumptuous of me, but I'm making some changes here before merging:

  • The "if there exists" construction is pretty formal, so I rewrote the comments that used it
  • A lot of the comments seemed pretty verbose, so I abbreviated most, leaving block comments only for things that obviously required special explanation
  • I removed any mention of "only handling DROP EXTENSION", which won't make sense unless the reader knows we removed the code to handle DROP TABLE
  • When I viewed your method in my editor, it had many levels of nesting, requiring long function calls to split parameters across many lines (up to five!). I'll explain the fix to this below
  • I renamed the PgShardProcessUtilityDropStatement function to be very clear about its purpose and changed its parameter to a DropStmt pointer

The only change in functionality I made is this: the original implementation would have printed a NOTICE if the user specified CASCADE even if no distributed tables existed. This would be misleading. Now I test early whether any distributed tables exist and just exit early it not.

Reducing Indentation Levels

If we have a construct like this:

void
SomeFunction(Params *param)
{
    Variable variable = param->field;
    /* ... */

    if (variable == VALUE)
    {
        Variable other = variable * 2;
        /* ... */
    }
    /* no more code in this function after if statement */
}

We can remove a level of nesting by doing this instead:

void
SomeFunction(Params *param)
{
    Variable variable = param->field;
    Variable other = -1;
    /* ... */

    if (variable != VALUE)
    {
        return;
    }

    other = variable * 2;
    /* code that used to be inside if block */
}

I'd say use this judiciously, because it can become a tax on the reader, but if you find yourself with five levels of nesting and you're inside some if block that could be replaced with a short-circuit (either a call to ereport(ERROR, ...) or a return), consider it.

@jasonmp85
Copy link
Collaborator

Oh yeah, and I changed the ERROR to use the precise language used by PostgreSQL when you try to drop a table that's dependent on another table.

A final note: You had errmsg("some message: %s", POUND_DEFINED_STRING_CONSTANT); in a couple of places. You can just let the compiler concatenate these strings for you: errmsg("some message: " POUND_DEFINED_STRING_CONSTANT);

jasonmp85 added a commit that referenced this pull request Feb 27, 2015
Forbids dropping extension if dist. tables exist.

cr: @jasonmp85
@jasonmp85 jasonmp85 merged commit 6549fde into develop Feb 27, 2015
@jasonmp85 jasonmp85 deleted the feature-issue#49 branch February 27, 2015 02:14
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.

Prevent deletion of metadata when still in use
2 participants