@@ -107,12 +107,11 @@ static HashVariableEntry *LastVariable = NULL;
107
107
static dlist_head * changesStack = NULL ;
108
108
static MemoryContext changesStackContext = NULL ;
109
109
110
- /* Returns a list of of vars changed at current subxact level */
111
- #define get_actual_changed_vars_list () \
110
+ /* Returns a lists of packages and variables changed at current subxact level */
111
+ #define get_actual_changes_list () \
112
112
( \
113
113
AssertMacro(changesStack != NULL), \
114
- (dlist_head_element(ChangesStackNode, \
115
- node, changesStack))->changedVarsList \
114
+ (dlist_head_element(ChangesStackNode, node, changesStack)) \
116
115
)
117
116
118
117
@@ -1192,8 +1191,8 @@ get_packages_stats(PG_FUNCTION_ARGS)
1192
1191
1193
1192
/* Fill data */
1194
1193
values [0 ] = PointerGetDatum (cstring_to_text (package -> name ));
1195
-
1196
- getMemoryTotalSpace (package -> hctxRegular , 0 , & regularSpace );
1194
+ if ( get_actual_pack_state ( package ) -> is_valid )
1195
+ getMemoryTotalSpace (package -> hctxRegular , 0 , & regularSpace );
1197
1196
getMemoryTotalSpace (package -> hctxTransact , 0 , & transactSpace );
1198
1197
totalSpace = regularSpace + transactSpace ;
1199
1198
values [1 ] = Int64GetDatum (totalSpace );
@@ -1535,7 +1534,7 @@ createSavepointVar(HashPackageEntry *package, HashVariableEntry *variable)
1535
1534
1536
1535
/* Release memory for variable */
1537
1536
history_entry_new = palloc0 (sizeof (ValueHistoryEntry ));
1538
- history_entry_prev = dlist_head_element ( ValueHistoryEntry , node , history );
1537
+ history_entry_prev = get_actual_var_state ( variable );
1539
1538
scalar = & history_entry_new -> value .scalar ;
1540
1539
* scalar = history_entry_prev -> value .scalar ;
1541
1540
@@ -1626,7 +1625,7 @@ createSavepointPack(HashPackageEntry *package)
1626
1625
1627
1626
history = & package -> packHistory ;
1628
1627
history_entry_new = MemoryContextAllocZero (ModuleContext , sizeof (PackHistoryEntry ));
1629
- history_entry_prev = dlist_head_element ( PackHistoryEntry , node , history );
1628
+ history_entry_prev = get_actual_pack_state ( package );
1630
1629
history_entry_new -> is_valid = history_entry_prev -> is_valid ;
1631
1630
dlist_push_head (history , & history_entry_new -> node );
1632
1631
}
@@ -1666,8 +1665,8 @@ releaseSavepointPack(HashPackageEntry *package)
1666
1665
/* Remove package from packagesHash */
1667
1666
hash_search (packagesHash , package -> name , HASH_REMOVE , & found );
1668
1667
/*
1669
- *Delete a variable from the change history of the overlying
1670
- *transaction level.
1668
+ * Delete a variable from the change history of the overlying
1669
+ * transaction level (head of 'changesStack' at this point)
1671
1670
*/
1672
1671
if (!dlist_is_empty (changesStack ))
1673
1672
removeFromChangedVars (package );
@@ -1865,7 +1864,7 @@ addToChangedPacks(HashPackageEntry *package)
1865
1864
{
1866
1865
ChangedPacksNode * cpn ;
1867
1866
1868
- csn = dlist_head_element ( ChangesStackNode , node , changesStack );
1867
+ csn = get_actual_changes_list ( );
1869
1868
cpn = makeChangedPacksNode (csn -> ctx , package );
1870
1869
dlist_push_head (csn -> changedPacksList , & cpn -> node );
1871
1870
@@ -1898,7 +1897,7 @@ addToChangedVars(HashPackageEntry *package, HashVariableEntry *variable)
1898
1897
{
1899
1898
ChangedVarsNode * cvn ;
1900
1899
1901
- csn = dlist_head_element ( ChangesStackNode , node , changesStack );
1900
+ csn = get_actual_changes_list ( );
1902
1901
cvn = makeChangedVarsNode (csn -> ctx , package , variable );
1903
1902
dlist_push_head (csn -> changedVarsList , & cvn -> node );
1904
1903
@@ -1908,21 +1907,37 @@ addToChangedVars(HashPackageEntry *package, HashVariableEntry *variable)
1908
1907
}
1909
1908
1910
1909
/*
1911
- * Remove from the changes list the variables of the deleted package
1910
+ * Remove from the changes list a deleted package
1912
1911
*/
1913
1912
static void
1914
1913
removeFromChangedVars (HashPackageEntry * package )
1915
1914
{
1916
- dlist_mutable_iter var_miter ;
1917
- dlist_head * changedVarsList ;
1915
+ dlist_mutable_iter var_miter ,
1916
+ pack_miter ;
1917
+ dlist_head * changedVarsList ,
1918
+ * changedPacksList ;
1918
1919
1919
- changedVarsList = get_actual_changed_vars_list ();
1920
+ /* First remove corresponding variables from changedVarsList */
1921
+ changedVarsList = get_actual_changes_list ()-> changedVarsList ;
1920
1922
dlist_foreach_modify (var_miter , changedVarsList )
1921
1923
{
1922
- ChangedVarsNode * cvn_cur = dlist_container (ChangedVarsNode , node , var_miter .cur );
1924
+ ChangedVarsNode * cvn_cur = dlist_container (ChangedVarsNode , node ,
1925
+ var_miter .cur );
1923
1926
if (cvn_cur -> package == package )
1924
1927
dlist_delete (& cvn_cur -> node );
1925
1928
}
1929
+ /* Now remove package itself from changedPacksList */
1930
+ changedPacksList = get_actual_changes_list ()-> changedPacksList ;
1931
+ dlist_foreach_modify (pack_miter , changedPacksList )
1932
+ {
1933
+ ChangedPacksNode * cpn_cur = dlist_container (ChangedPacksNode , node ,
1934
+ pack_miter .cur );
1935
+ if (cpn_cur -> package == package )
1936
+ {
1937
+ dlist_delete (& cpn_cur -> node );
1938
+ break ;
1939
+ }
1940
+ }
1926
1941
}
1927
1942
1928
1943
/*
0 commit comments