@@ -107,12 +107,11 @@ static HashVariableEntry *LastVariable = NULL;
107107static dlist_head * changesStack = NULL ;
108108static MemoryContext changesStackContext = NULL ;
109109
110- /* Returns alist ofof vars changed at current subxact level */
111- #define get_actual_changed_vars_list () \
110+ /* Returns alists ofpackages and variables changed at current subxact level */
111+ #define get_actual_changes_list () \
112112( \
113113AssertMacro(changesStack != NULL), \
114- (dlist_head_element(ChangesStackNode, \
115- node, changesStack))->changedVarsList \
114+ (dlist_head_element(ChangesStackNode, node, changesStack)) \
116115)
117116
118117
@@ -1192,8 +1191,8 @@ get_packages_stats(PG_FUNCTION_ARGS)
11921191
11931192/* Fill data */
11941193values [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 );
11971196getMemoryTotalSpace (package -> hctxTransact ,0 ,& transactSpace );
11981197totalSpace = regularSpace + transactSpace ;
11991198values [1 ]= Int64GetDatum (totalSpace );
@@ -1535,7 +1534,7 @@ createSavepointVar(HashPackageEntry *package, HashVariableEntry *variable)
15351534
15361535/* Release memory for variable */
15371536history_entry_new = palloc0 (sizeof (ValueHistoryEntry ));
1538- history_entry_prev = dlist_head_element ( ValueHistoryEntry , node , history );
1537+ history_entry_prev = get_actual_var_state ( variable );
15391538scalar = & history_entry_new -> value .scalar ;
15401539* scalar = history_entry_prev -> value .scalar ;
15411540
@@ -1626,7 +1625,7 @@ createSavepointPack(HashPackageEntry *package)
16261625
16271626history = & package -> packHistory ;
16281627history_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 );
16301629history_entry_new -> is_valid = history_entry_prev -> is_valid ;
16311630dlist_push_head (history ,& history_entry_new -> node );
16321631}
@@ -1666,8 +1665,8 @@ releaseSavepointPack(HashPackageEntry *package)
16661665/* Remove package from packagesHash */
16671666hash_search (packagesHash ,package -> name ,HASH_REMOVE ,& found );
16681667/*
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)
16711670 */
16721671if (!dlist_is_empty (changesStack ))
16731672removeFromChangedVars (package );
@@ -1865,7 +1864,7 @@ addToChangedPacks(HashPackageEntry *package)
18651864{
18661865ChangedPacksNode * cpn ;
18671866
1868- csn = dlist_head_element ( ChangesStackNode , node , changesStack );
1867+ csn = get_actual_changes_list ( );
18691868cpn = makeChangedPacksNode (csn -> ctx ,package );
18701869dlist_push_head (csn -> changedPacksList ,& cpn -> node );
18711870
@@ -1898,7 +1897,7 @@ addToChangedVars(HashPackageEntry *package, HashVariableEntry *variable)
18981897{
18991898ChangedVarsNode * cvn ;
19001899
1901- csn = dlist_head_element ( ChangesStackNode , node , changesStack );
1900+ csn = get_actual_changes_list ( );
19021901cvn = makeChangedVarsNode (csn -> ctx ,package ,variable );
19031902dlist_push_head (csn -> changedVarsList ,& cvn -> node );
19041903
@@ -1908,21 +1907,37 @@ addToChangedVars(HashPackageEntry *package, HashVariableEntry *variable)
19081907}
19091908
19101909/*
1911- * Remove from the changes listthe variables of the deleted package
1910+ * Remove from the changes lista deleted package
19121911 */
19131912static void
19141913removeFromChangedVars (HashPackageEntry * package )
19151914{
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 ;
19181919
1919- changedVarsList = get_actual_changed_vars_list ();
1920+ /* First remove corresponding variables from changedVarsList */
1921+ changedVarsList = get_actual_changes_list ()-> changedVarsList ;
19201922dlist_foreach_modify (var_miter ,changedVarsList )
19211923{
1922- ChangedVarsNode * cvn_cur = dlist_container (ChangedVarsNode ,node ,var_miter .cur );
1924+ ChangedVarsNode * cvn_cur = dlist_container (ChangedVarsNode ,node ,
1925+ var_miter .cur );
19231926if (cvn_cur -> package == package )
19241927dlist_delete (& cvn_cur -> node );
19251928}
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+ }
19261941}
19271942
19281943/*