--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.store.raw.data.ChainAllocPageOperation\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.PhysicalPageOperation;\r
+import org.apache.derby.impl.store.raw.data.BasePage;\r
+\r
+import org.apache.derby.iapi.services.io.FormatIdUtil;\r
+import org.apache.derby.iapi.services.io.StoredFormatIds;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.store.raw.ContainerHandle;\r
+import org.apache.derby.iapi.store.raw.data.RawContainerHandle;\r
+import org.apache.derby.iapi.store.raw.Transaction;\r
+import org.apache.derby.iapi.store.raw.log.LogInstant;\r
+\r
+import org.apache.derby.iapi.services.io.CompressedNumber;\r
+\r
+import java.io.OutputStream;\r
+import java.io.ObjectOutput;\r
+import java.io.IOException;\r
+import org.apache.derby.iapi.services.io.LimitObjectInput;\r
+import java.io.ObjectInput;\r
+\r
+\r
+/**\r
+\r
+Log operation to implement compressing space from a container and returning\r
+it to the operating system.\r
+\r
+**/\r
+\r
+public class CompressSpacePageOperation extends PhysicalPageOperation\r
+{\r
+ /**************************************************************************\r
+ * Fields of the class\r
+ **************************************************************************\r
+ */\r
+\r
+ /**\r
+ * The new highest page on this allocation page. The number is the\r
+ * offset of the page in the array of pages maintained by this \r
+ * allocation page, for instance a value of 0 indicates all page except\r
+ * the first one are to be truncated. If all pages are truncated then \r
+ * the offset is set to -1.\r
+ **/\r
+ protected int newHighestPage; \r
+\r
+ /**\r
+ * The number of allocated pages in this allocation page prior to \r
+ * the truncate. Note that all pages from NewHighestPage+1 through\r
+ * newHighestPage+num_pages_truncated should be FREE.\r
+ **/\r
+ protected int num_pages_truncated; \r
+\r
+ /**************************************************************************\r
+ * Constructors for This class:\r
+ **************************************************************************\r
+ */\r
+ public CompressSpacePageOperation(\r
+ AllocPage allocPage, \r
+ int highest_page, \r
+ int num_truncated)\r
+ throws StandardException\r
+ {\r
+ super(allocPage);\r
+\r
+ newHighestPage = highest_page;\r
+ num_pages_truncated = num_truncated;\r
+ }\r
+ \r
+ /**************************************************************************\r
+ * Public Methods of Formatable interface.\r
+ **************************************************************************\r
+ */\r
+\r
+ // no-arg constructor, required by Formatable \r
+ public CompressSpacePageOperation() { super(); }\r
+\r
+ public void writeExternal(ObjectOutput out) throws IOException \r
+ {\r
+ super.writeExternal(out);\r
+ if( !(this instanceof CompressSpacePageOperation10_2) )\r
+ {\r
+ out.writeInt(newHighestPage);\r
+ CompressedNumber.writeInt(out, num_pages_truncated);\r
+ }\r
+ }\r
+\r
+ /**\r
+ @exception IOException error reading from log stream\r
+ @exception ClassNotFoundException cannot read object from input\r
+ */\r
+ public void readExternal(ObjectInput in)\r
+ throws IOException, ClassNotFoundException\r
+ {\r
+ super.readExternal(in);\r
+ if( !(this instanceof CompressSpacePageOperation10_2) )\r
+ {\r
+ newHighestPage = in.readInt();\r
+ num_pages_truncated = CompressedNumber.readInt(in);\r
+ }\r
+ }\r
+\r
+ /**\r
+ Return my format identifier.\r
+ */\r
+ public int getTypeFormatId() {\r
+ return StoredFormatIds.LOGOP_COMPRESS_SPACE;\r
+ }\r
+\r
+ /**************************************************************************\r
+ * Public Methods of Loggable interface.\r
+ **************************************************************************\r
+ */\r
+\r
+ /**\r
+ * Compress space from container.\r
+ * <p>\r
+ * Compress the indicate space from the container, returning the free\r
+ * pages to the OS. Update the allocation page to reflect the file\r
+ * change.\r
+ *\r
+ * @param tran transaction doing the operation.\r
+ * @param instant log instant for this operation.\r
+ * @param in unused by this log operation.\r
+ *\r
+ * @exception StandardException Standard exception policy.\r
+ **/\r
+ public final void doMe(\r
+ Transaction tran, \r
+ LogInstant instant, \r
+ LimitObjectInput in) \r
+ throws StandardException\r
+ {\r
+ if (SanityManager.DEBUG) \r
+ {\r
+ SanityManager.ASSERT(this.page instanceof AllocPage);\r
+ }\r
+\r
+ ((AllocPage)page).compressSpace(\r
+ instant, newHighestPage, num_pages_truncated);\r
+ }\r
+\r
+ /**************************************************************************\r
+ * Public Methods of Undoable interface.\r
+ **************************************************************************\r
+ */\r
+\r
+ /**\r
+ * Compress space undo.\r
+ * <p>\r
+ *\r
+ * @exception StandardException Thrown by methods I call \r
+ * @see PhysicalPageOperation#undoMe\r
+ **/\r
+ public void undoMe(\r
+ Transaction xact, \r
+ BasePage undoPage, \r
+ LogInstant CLRInstant, \r
+ LimitObjectInput in)\r
+ throws StandardException\r
+ {\r
+ if (SanityManager.DEBUG) \r
+ {\r
+ SanityManager.ASSERT(undoPage != null, "undo Page null");\r
+ SanityManager.ASSERT(\r
+ undoPage instanceof AllocPage, \r
+ "undo Page is not an allocPage");\r
+ }\r
+\r
+ ((AllocPage)undoPage).undoCompressSpace(\r
+ CLRInstant, newHighestPage, num_pages_truncated);\r
+ }\r
+\r
+ /*\r
+ * method to support BeforeImageLogging\r
+ */\r
+ public void restoreMe(\r
+ Transaction xact, \r
+ BasePage undoPage, \r
+ LogInstant CLRinstant, \r
+ LimitObjectInput in)\r
+ {\r
+ // nobody should be calling this since there is no corresponding \r
+ // BI operation.\r
+ if (SanityManager.DEBUG)\r
+ SanityManager.THROWASSERT(\r
+ "cannot call restoreMe on CompressSpaceOperation.");\r
+ }\r
+\r
+\r
+ /** debug */\r
+ public String toString()\r
+ {\r
+ if (SanityManager.DEBUG)\r
+ {\r
+ String str = super.toString();\r
+ str += " CompressSpaceOperation: " + \r
+ "newHighestPage = " + newHighestPage +\r
+ ";num_pages_truncated = " + num_pages_truncated +\r
+ " to " + getPageId();\r
+\r
+ return str;\r
+ }\r
+ else\r
+ return null;\r
+ }\r
+}\r