Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / impl / store / raw / data / LoggableAllocActions.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/store/raw/data/LoggableAllocActions.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/store/raw/data/LoggableAllocActions.java
new file mode 100644 (file)
index 0000000..a13fd21
--- /dev/null
@@ -0,0 +1,150 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.store.raw.data.LoggableAllocActions\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to you under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.store.raw.data;\r
+\r
+import org.apache.derby.impl.store.raw.data.AllocationActions;\r
+import org.apache.derby.impl.store.raw.data.BasePage;\r
+\r
+import org.apache.derby.iapi.store.raw.RawStoreFactory;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.services.io.FormatIdUtil;\r
+\r
+import org.apache.derby.iapi.store.raw.Loggable;\r
+import org.apache.derby.iapi.store.raw.xact.RawTransaction;\r
+import org.apache.derby.iapi.store.raw.log.LogInstant;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+public class LoggableAllocActions implements AllocationActions {\r
+\r
+       /**\r
+               Set the allocation status of pageNumber to doStatus.  To undo this\r
+               operation, set the allocation status of pageNumber to undoStatus\r
+               \r
+               @param t                                The transaction\r
+               @param allocPage                the allocation page\r
+               @param pageNumber               the page to allocation or deallocation\r
+               @param doStatus                 set the allocation status of the page this value\r
+               @param undoStatus               on undo, set the allocation status of the page\r
+                                                               this value \r
+\r
+               @exception StandardException    Standard Derby error policy\r
+       */\r
+       public void actionAllocatePage(RawTransaction t, BasePage allocPage, \r
+                                                                  long pageNumber, int doStatus, int undoStatus)\r
+                throws StandardException\r
+       {\r
+               Loggable lop = new AllocPageOperation((AllocPage)allocPage, pageNumber, doStatus, undoStatus);\r
+\r
+               // mark the page as pre-dirtied so that if a checkpoint happens after\r
+               // the log record is sent to the log stream, the cache cleaning will\r
+               // wait for this change.\r
+               allocPage.preDirty();\r
+\r
+               t.logAndDo(lop);\r
+       }\r
+\r
+       /**\r
+               Chain one allocation page to the next.\r
+\r
+               @param t                                The transaction\r
+               @param allocPage                the allocation page whose next page chain needs\r
+                                                               to be changed\r
+               @param pageNumber               the next allocation page's number \r
+               @param pageOffset               the next allocation page's page offset\r
+\r
+               @exception StandardException    Standard Derby error policy\r
+       */\r
+       public void actionChainAllocPage(RawTransaction t, BasePage allocPage, \r
+                                                               long pageNumber, long pageOffset)\r
+                throws StandardException\r
+       {\r
+               Loggable lop = new ChainAllocPageOperation((AllocPage)allocPage, pageNumber, pageOffset);\r
+\r
+               // mark the page as pre-dirtied so that if a checkpoint happens after\r
+               // the log record is sent to the log stream, the cache cleaning will\r
+               // wait for this change.\r
+               allocPage.preDirty();\r
+\r
+               t.logAndDo(lop);\r
+       }\r
+\r
+    /**\r
+     * Compress free pages.\r
+     * <p>\r
+     * Compress the free pages at the end of the range maintained by\r
+     * this allocation page.  All pages being compressed should be FREE.\r
+     * Only pages in the last allocation page can be compressed.\r
+     * <p>\r
+     *\r
+     * @param t                                        The transaction\r
+     * @param allocPage                        the allocation page to do compress on.\r
+     * @param new_highest_page      The new highest page on this allocation \r
+     *                              page.  The number is the offset of the page\r
+     *                              in the array of pages maintained by this \r
+     *                              allocation page, for instance a value of 0 \r
+     *                              indicates all page except the first one are\r
+     *                              to be truncated.  If all pages are \r
+     *                              truncated then the offset is set to -1.\r
+     * @param num_pages_truncated   The number of allocated pages in this \r
+     *                              allocation page prior to the truncate.  \r
+     *                              Note that all pages from NewHighestPage+1 \r
+     *                              through newHighestPage+num_pages_truncated \r
+     *                              should be FREE.\r
+     *\r
+        * @exception  StandardException  Standard exception policy.\r
+     **/\r
+    public void actionCompressSpaceOperation(\r
+       RawTransaction  t,\r
+    BasePage        allocPage, \r
+    int             new_highest_page, \r
+    int             num_pages_truncated)\r
+        throws StandardException\r
+    {\r
+        Loggable lop = null;\r
+        \r
+        // DERBY-606. As part of the fix for DERBY-606, negative values can be \r
+        // written to CompressSpace operation Log Records. In order for this \r
+        // fix to be backword compatible, we make sure that the implementation \r
+        // behaves the old way in soft upgrade mode, here. This is achieved by \r
+        // passing null to feature argument.\r
+        if( t.getLogFactory().checkVersion(\r
+                RawStoreFactory.DERBY_STORE_MAJOR_VERSION_10,\r
+                RawStoreFactory.DERBY_STORE_MINOR_VERSION_3,\r
+                null) )\r
+        {\r
+            lop = \r
+                new CompressSpacePageOperation(\r
+                    (AllocPage)allocPage, \r
+                    new_highest_page, \r
+                    num_pages_truncated);\r
+        } else {\r
+            lop = new CompressSpacePageOperation10_2(\r
+                    (AllocPage)allocPage, \r
+                    new_highest_page, \r
+                    num_pages_truncated);\r
+        }\r
+        allocPage.preDirty();\r
+\r
+        t.logAndDo(lop);\r
+    }\r
+}\r