Skip to content

Add support of package removal rollback #11

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

Merged
merged 15 commits into from
Jun 21, 2018

Conversation

CherkashinSergey
Copy link
Collaborator

Можно откатывать как удаление одного пакета переменных, так и pgv_free(). Теперь обычные и транзакционные переменные хранятся в разных хэш-таблицах, сами пакеты имеют такую же историю состояний, как и переменные.

@za-arthur
Copy link
Contributor

@CherkashinSergey , похоже pg_variables на тестах падает.

@codecov-io
Copy link

codecov-io commented May 25, 2018

Codecov Report

Merging #11 into master will increase coverage by 0.38%.
The diff coverage is 97.5%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #11      +/-   ##
==========================================
+ Coverage   93.91%   94.29%   +0.38%     
==========================================
  Files           4        4              
  Lines         772      876     +104     
==========================================
+ Hits          725      826     +101     
- Misses         47       50       +3
Impacted Files Coverage Δ
pg_variables_record.c 93.27% <100%> (-0.85%) ⬇️
pg_variables.c 94.33% <97.39%> (+0.63%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9d3e182...4194f40. Read the comment docs.

pg_variables.c Outdated
@@ -144,7 +157,9 @@ variable_set(text *package_name, text *var_name,
scalar->is_null = is_null;
if (!scalar->is_null)
{
oldcxt = MemoryContextSwitchTo(package->hctx);
oldcxt = MemoryContextSwitchTo(is_transactional ?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Предлагаю выделить выбор контекста is_transactional ? ... : ... в отдельный макрос, принимающий в качестве аргумента package.

pg_variables.c Outdated
hash_seq_init(&vstat, package->variablesHash);
while ((variable =
(HashVariableEntry *) hash_seq_search(&vstat)) != NULL)
for(int i=0; i < 2; i++)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Объявление переменной в цикле не соответствует ansi c89.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Я мог проглядеть похожие ошибки, советую компилировать с CFLAGS=... -std=c89. Если найдем что-то еще, нужно будет поправить. Мне самому больше нравится не выносить переменные из шапки цикла, но это не соответствует стилю PostgreSQL, а значит, нежелательно.

pg_variables.c Outdated
package->hctxRegular = AllocSetContextCreate(ModuleContext,
PGV_MCXT_VARS,
ALLOCSET_DEFAULT_SIZES);
sprintf(hash_name, "%s variables hash for package \"%s\"",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Для буферов всегда надо использовать snprintf.

pg_variables.c Outdated
{
switch (event)
{
case XACT_EVENT_PRE_COMMIT:
applyActionOnChangedVars(RELEASE_SAVEPOINT);
popChangedVarsStack();
proceedChanges(RELEASE_SAVEPOINT);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Я думаю, имелся в виду все-таки process, а не proceed.

pg_variables.c Outdated
hash_seq_init(&vstat, package->variablesHash);
while ((variable =
(HashVariableEntry *) hash_seq_search(&vstat)) != NULL)
for(int i=0; i < 2; i++)
Copy link
Collaborator

@funbringer funbringer May 28, 2018

Choose a reason for hiding this comment

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

Я посмотрел код в целом, и мне кажется, что как-то много дублирующихся фрагментов.

Например, addToChanged{Packs,Vars}(), is{Var,Pack}ChangedInUpperTrans() итд абсолютно эквивалентны с точностью до пары строчек, в removeFromChangedVars() два почти одинаковых цикла. Мне не нравится, что практически не производится никаких попыток сжать код.

Я думаю, значительную часть кода по управлению стеками можно было бы выделить в отдельные функции, с возможностью задать дополнительные обработчики для действий, зависящих от типа стека.

MemoryContext ctx;
} ChangedVarsStackNode;
} ChangesStackNode;
Copy link
Contributor

Choose a reason for hiding this comment

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

Мне кажется тут название непоследовательное. Может ChangedStackNode?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Подразумевается "стэк изменеий". Потому что в самом стеке лежит история изменений как переменных, так и пакетов. "ChangedStack" больше выглядит как "изменённый стэк".

pg_variables.h Outdated
@@ -137,13 +159,17 @@ extern void insert_savepoint(HashVariableEntry *variable,
MemoryContext packageContext);

/* Internal macros to manage with dlist structure */
#define get_actual_value_scalar(variable) \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Зачем?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Для того, чтобы можно было нормально использовать шаблоны, пришлось привести эти макросы к одному виду.

pg_variables.h Outdated
dlist_node node;
bool is_valid;
int level;
} PackHistoryEntry;
Copy link
Contributor

Choose a reason for hiding this comment

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

Пока еще не все смотрел, но кажется тут можно реализовать наследование. VarHistoryEntry наследуется от PackHistoryEntry.

Copy link
Contributor

@za-arthur za-arthur Jun 6, 2018

Choose a reason for hiding this comment

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

typedef struct HistoryEntry
{
    dlist_node	node;
    bool is_valid;
    int level;
} HistoryEntry;
typedef struct VarHistoryEntry
{
    HistoryEntry entry;
    union
    {
      ScalarVar scalar;
      RecordVar record;
    } value;
} VarHistoryEntry;
/* ... */
static bool
func(HistoryEntry *entry)
{
    /* Do something */
    return entry->is_valid;
}
/* ... */
{
    HistoryEntry *entry = /* ... */;
    if (is_var)
    {
      VarHistoryEntry *var_entry = (VarHistoryEntry *) entry;
      /* ... */
    }
    return func(entry);
}

@za-arthur za-arthur merged commit 26c5328 into postgrespro:master Jun 21, 2018
@za-arthur
Copy link
Contributor

Смержил!

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