KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > raw > data > BaseContainer


1 /*
2
3    Derby - Class org.apache.derby.impl.store.raw.data.BaseContainer
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.store.raw.data;
23
24 import org.apache.derby.iapi.reference.SQLState;
25 import org.apache.derby.iapi.services.locks.Lockable;
26 import org.apache.derby.iapi.services.locks.Latch;
27 import org.apache.derby.iapi.services.locks.C_LockFactory;
28 import org.apache.derby.iapi.services.sanity.SanityManager;
29
30 import org.apache.derby.iapi.error.StandardException;
31
32 import org.apache.derby.iapi.store.access.TransactionController;
33 import org.apache.derby.iapi.store.access.SpaceInfo;
34
35 import org.apache.derby.iapi.store.raw.ContainerHandle;
36 import org.apache.derby.iapi.store.raw.LockingPolicy;
37 import org.apache.derby.iapi.store.raw.Page;
38 import org.apache.derby.iapi.store.raw.PageKey;
39 import org.apache.derby.iapi.store.raw.PageTimeStamp;
40 import org.apache.derby.iapi.store.raw.RecordHandle;
41 import org.apache.derby.iapi.store.raw.Transaction;
42 import org.apache.derby.iapi.store.raw.ContainerKey;
43 import org.apache.derby.iapi.store.raw.data.RawContainerHandle;
44 import org.apache.derby.iapi.store.raw.log.LogInstant;
45 import org.apache.derby.iapi.store.raw.xact.RawTransaction;
46
47 import org.apache.derby.iapi.util.ByteArray;
48
49 import java.util.Properties JavaDoc;
50 import java.util.Hashtable JavaDoc;
51
52 /**
53     BaseContainer is an abstract class that provides the locking bahaviour
54     for an object representing an active container, that is the actual
55     storage container, not the ContainerHandle interface. This class is designed
56     so that it can change the container it represents to avoid creating
57     a new object for every container.
58     <P>
59     This object implements lockable to provide an object to lock while a page is being
60     allocated.
61     <BR> MT - Mutable - mutable identity :
62 */

63 abstract class BaseContainer implements Lockable {
64
65     /**
66         Identity of the container.
67
68         <BR> MT - Mutable
69     */

70     protected ContainerKey identity;
71
72     
73     /**
74         Dropped state of the container.
75
76         <BR> MT - mutable : single thread required. Either the container must be exclusive
77         locked by this thread, or the container must have no identity (ie. it is being created
78         or opened).
79     */

80     protected boolean isDropped;
81
82
83     /**
84         Committed Drop state of the container. If a post comit action
85         determined that the drop container operation is committed, the whole
86         container may be removed and space reclaimed.
87
88         <BR> MT - mutable : single thread required. Either the container must be exclusive
89         locked by this thread, or the container must have no identity (ie. it is being created
90         or opened).
91     */

92     protected boolean isCommittedDrop;
93
94
95     /**
96         Is reusable recordId. By default, record Ids are not reusable when a
97         page is reused. However, under special circumstances, clients to raw
98         store may decide that record Ids may be reused after the page is
99         reused. When this flag is set, pages that are reused will have its
100         next recordId set to RecordHandle.FIRST_RECORD_ID
101     */

102     protected boolean isReusableRecordId = false;
103
104     BaseContainer() {
105     }
106
107     /*
108     ** portions of Cacheable interface, interface is actually implemented by
109     ** sub-class. This section also contains methods related to this interface.
110     */

111
112     protected void fillInIdentity(ContainerKey key) {
113
114         if (SanityManager.DEBUG) {
115             SanityManager.ASSERT(identity == null || (identity == key));
116         }
117
118         identity = key;
119     }
120
121     public void clearIdentity() {
122         if (SanityManager.DEBUG) {
123             SanityManager.ASSERT(identity != null);
124         }
125
126         identity = null;
127     }
128
129     public Object JavaDoc getIdentity() {
130         return identity;
131     }
132
133     /*
134     ** Methods from Lockable, just require a single exclusive locker
135     */

136
137     public void lockEvent(Latch lockInfo) {
138         if (SanityManager.DEBUG) {
139             SanityManager.ASSERT(identity != null);
140         }
141     }
142
143     public boolean requestCompatible(Object JavaDoc requestedQualifier, Object JavaDoc grantedQualifier) {
144         if (SanityManager.DEBUG) {
145             SanityManager.ASSERT(identity != null);
146         }
147         return false;
148     }
149
150     public boolean lockerAlwaysCompatible() {
151         if (SanityManager.DEBUG) {
152             SanityManager.ASSERT(identity != null);
153         }
154         return false;
155     }
156
157     public void unlockEvent(Latch lockInfo) {
158         if (SanityManager.DEBUG) {
159             SanityManager.ASSERT(identity != null);
160         }
161     }
162
163     /*
164     ** Implementation specific methods
165     */

166
167
168     /**
169         Release free space to the OS.
170         <P>
171         As is possible release any free space to the operating system. This
172         will usually mean releasing any free pages located at the end of the
173         file using the java truncate() interface.
174
175         @exception StandardException Standard Cloudscape error policy
176     */

177     public void compressContainer(BaseContainerHandle handle)
178         throws StandardException
179     {
180         RawTransaction ntt = handle.getTransaction().startNestedTopTransaction();
181
182         int mode = handle.getMode();
183
184         if (SanityManager.DEBUG)
185         {
186             SanityManager.ASSERT((mode & ContainerHandle.MODE_FORUPDATE) ==
187                                  ContainerHandle.MODE_FORUPDATE,
188                                  "addPage handle not for update");
189         }
190
191         // if we are not in the same transaction as the one which created the
192
// container and the container may have logged some operation already,
193
// then we need to log allocation regardless of whether user changes
194
// are logged. Otherwise, the database will be corrupted if it
195
// crashed.
196
if ((mode & ContainerHandle.MODE_CREATE_UNLOGGED) == 0 &&
197             (mode & ContainerHandle.MODE_UNLOGGED) ==
198                         ContainerHandle.MODE_UNLOGGED)
199             mode &= ~ContainerHandle.MODE_UNLOGGED;
200
201         // make a handle which is tied to the ntt, not to the user transaction
202
// this handle is tied to. The container is already locked by the
203
// user transaction, open it nolock
204
BaseContainerHandle allocHandle = (BaseContainerHandle)
205             ntt.openContainer(identity, (LockingPolicy)null, mode);
206
207         if (allocHandle == null)
208         {
209             throw StandardException.newException(
210                     SQLState.DATA_ALLOC_NTT_CANT_OPEN,
211                     new Long JavaDoc(getSegmentId()),
212                     new Long JavaDoc(getContainerId()));
213         }
214
215         // Latch this container, the commit will release the latch
216
ntt.getLockFactory().lockObject(
217                 ntt, ntt, this, null, C_LockFactory.WAIT_FOREVER);
218
219         try
220         {
221             incrementReusableRecordIdSequenceNumber();
222             compressContainer(ntt, allocHandle);
223         }
224         finally
225         {
226             ntt.commit();
227
228             ntt.close();
229         }
230     }
231
232     /**
233      * Get the reusable RecordId sequence number for the
234      * container. This sequence number should be incremented every time
235      * there is an operation which may cause RecorIds to be reused.
236      * This method can be used by clients to check if a RecordId they
237      * obtained is still guaranteed to be valid.
238      * If the sequence number has changed, the RecordId may have been
239      * reused for another row.
240      * @return sequence number for reusable RecordId
241      */

242     public abstract long getReusableRecordIdSequenceNumber();
243
244     /**
245      * Increment the reusable RecordId sequence number.
246      */

247     protected abstract void incrementReusableRecordIdSequenceNumber();
248     
249
250     /**
251         Add a page to this container.
252
253         <BR> MT - thread aware -
254
255         The add page operation involves 2 transactions, one is the user
256         transaction (the transaction which owns the passed in handle), the
257         other one is a NestedTopTransaction created by this BaseContainer.
258
259         The nestedTopTransaction is used by the underlying container to change
260         high contention structures, such as link list anchor or bit map pages.
261         The nestedTopTransaction commits or aborts before this routine returns.
262
263         The user transaction is used to latch the newly created page.
264
265         @exception StandardException Standard Cloudscape error policy
266     */

267     public Page addPage(BaseContainerHandle handle, boolean isOverflow) throws StandardException {
268         
269         RawTransaction ntt = handle.getTransaction().startNestedTopTransaction();
270
271         int mode = handle.getMode();
272
273         if (SanityManager.DEBUG)
274         {
275             SanityManager.ASSERT((mode & ContainerHandle.MODE_FORUPDATE) ==
276                                  ContainerHandle.MODE_FORUPDATE,
277                                  "addPage handle not for update");
278         }
279
280         // if we are not in the same transaction as the one which created the
281
// container and the container may have logged some operation already,
282
// then we need to log allocation regardless of whether user changes
283
// are logged. Otherwise, the database will be corrupted if it
284
// crashed.
285
if ((mode & ContainerHandle.MODE_CREATE_UNLOGGED) == 0 &&
286             (mode & ContainerHandle.MODE_UNLOGGED) ==
287                         ContainerHandle.MODE_UNLOGGED)
288             mode &= ~ContainerHandle.MODE_UNLOGGED;
289
290         // make a handle which is tied to the ntt, not to the user transaction this
291
// handle is tied to. The container is already locked by the user transaction,
292
// open it nolock
293
BaseContainerHandle allocHandle = (BaseContainerHandle)ntt.openContainer
294             (identity, (LockingPolicy)null, mode);
295
296         if (allocHandle == null)
297         {
298             throw StandardException.newException(
299                     SQLState.DATA_ALLOC_NTT_CANT_OPEN,
300                     new Long JavaDoc(getSegmentId()),
301                     new Long JavaDoc(getContainerId()));
302         }
303
304         // Latch this container, the commit will release the latch
305
ntt.getLockFactory().lockObject(
306                 ntt, ntt, this, null, C_LockFactory.WAIT_FOREVER);
307
308         BasePage newPage = null;
309         try
310         {
311             newPage = newPage(handle, ntt, allocHandle, isOverflow);
312         }
313         finally
314         {
315             if (newPage != null)
316             {
317                 // it is ok to commit without syncing, as it is ok if this
318
// transaction never makes it to the db, if no subsequent
319
// log record makes it to the log. If any subsequent log
320
// record is sync'd then this transaction will be sync'd
321
// as well.
322
ntt.commitNoSync(Transaction.RELEASE_LOCKS);
323             }
324             else
325             {
326                 ntt.abort();
327             }
328             ntt.close();
329         }
330
331         if (SanityManager.DEBUG) {
332             SanityManager.ASSERT(newPage.isLatched());
333         }
334
335         if (!this.identity.equals(newPage.getPageId().getContainerId())) {
336
337             if (SanityManager.DEBUG) {
338                 SanityManager.THROWASSERT("BaseContainer.addPage(), just got a new page from a different container"
339                     + "\n this.identity = " + this.identity
340                     + "\n newPage.getPageId().getContainerId() = " + newPage.getPageId().getContainerId()
341                     + "\n handle is: " + handle
342                     + "\n allocHandle is: " + allocHandle
343                     + "\n this container is: " + this);
344             }
345
346             throw StandardException.newException(
347                     SQLState.DATA_DIFFERENT_CONTAINER,
348                     this.identity, newPage.getPageId().getContainerId());
349         }
350
351         return newPage;
352     }
353
354     /**
355      * Request the system properties associated with a container.
356      * <p>
357      * Request the value of properties that are associated with a container.
358      * The following properties can be requested:
359      * derby.storage.pageSize
360      * derby.storage.pageReservedSpace
361      * derby.storage.minimumRecordSize
362      * <p>
363      * To get the value of a particular property add it to the property list,
364      * and on return the value of the property will be set to it's current
365      * value. For example:
366      *
367      * get_prop(BaseContainer base)
368      * {
369      * Properties prop = new Properties();
370      * prop.put("derby.storage.pageSize", "");
371      * base.getContainerProperties(prop);
372      *
373      * System.out.println(
374      * "container's page size = " +
375      * prop.getProperty("derby.storage.pageSize");
376      * }
377      *
378      * @param prop Property list to fill in.
379      *
380      * @exception StandardException Standard exception policy.
381      **/

382     public abstract void getContainerProperties(Properties JavaDoc prop)
383         throws StandardException;
384
385     /**
386         Remove a page from this container. The page will be unlatched by this
387         routine before it returns.
388
389         Unlike addPage, this method done as part of the user transaction.
390         The removed page is not usable by anyone until the user transaction
391         comits.
392         If the user transaction rolls back, the removed page is un-removed.
393
394         <BR> MT - thread aware -
395
396         @param handle the container handle that has opened the container and latched the page
397         @param page the latched page that is to be deallocated
398
399         @exception StandardException Standard Cloudscape error policy
400     */

401     protected void removePage(BaseContainerHandle handle, BasePage page)
402          throws StandardException
403     {
404         try
405         {
406             if (SanityManager.DEBUG)
407             {
408                 SanityManager.ASSERT(page.isLatched(), "page is not latched");
409             }
410
411             // get dealloc lock nowait on the page to be deallocated
412
// this lock is held until this transaction commits.
413
// then gc can free this page
414
RecordHandle deallocLock =
415                 page.makeRecordHandle(RecordHandle.DEALLOCATE_PROTECTION_HANDLE);
416
417             // don't get deallocLock wait because caller have a page latched
418
if (!getDeallocLock(handle, deallocLock,
419                                 false /* no wait */,
420                                 false /* not zeroDuration */))
421             {
422                 throw StandardException.newException(
423                         SQLState.DATA_CANNOT_GET_DEALLOC_LOCK,
424                         page.getIdentity());
425             }
426
427             deallocatePage(handle, page);
428         }
429         finally
430         {
431             if (page != null)
432                 page.unlatch();
433         }
434
435     }
436
437     /**
438         Get the special dealloc lock on the page - the lock is gotten by the
439         transaction that owns the container handle
440
441         @exception StandardException Standard Cloudscape error policy
442     */

443     protected boolean getDeallocLock(BaseContainerHandle handle,
444                                      RecordHandle deallocLock,
445                                      boolean wait,
446                                      boolean zeroDuration)
447          throws StandardException
448     {
449         // get deallocate lock on page so that the GC won't attempt to
450
// free and re-allocate it until the transaction commits
451
RawTransaction tran = handle.getTransaction();
452
453         LockingPolicy lp =
454             tran.newLockingPolicy(
455                 LockingPolicy.MODE_RECORD,
456                 TransactionController.ISOLATION_REPEATABLE_READ,
457                 true); // striterOK
458

459         PageKey pkey = new PageKey(identity, deallocLock.getPageNumber());
460         if (lp != null)
461         {
462             if (zeroDuration)
463                 return lp.zeroDurationLockRecordForWrite(
464                         tran, deallocLock, false, wait);
465             else
466                 return lp.lockRecordForWrite(tran, deallocLock, false, wait);
467         }
468         else
469         {
470             throw StandardException.newException(
471                     SQLState.DATA_CANNOT_GET_DEALLOC_LOCK, pkey);
472         }
473     }
474
475
476     /**
477         Get an allocation page and latch it.
478         @exception StandardException Standard Cloudscape error policy
479     */

480     protected Page getAllocPage(BaseContainerHandle handle, long pageNumber, boolean wait)
481          throws StandardException
482     {
483         return latchPage(handle, getAllocPage(pageNumber), wait);
484     }
485
486     /**
487         Get any page and latch it .
488         @exception StandardException Standard Cloudscape error policy
489     */

490     protected Page getAnyPage(BaseContainerHandle handle, long pageNumber, boolean wait)
491          throws StandardException
492     {
493         return latchPage(handle, getAnyPage(handle, pageNumber), wait);
494     }
495
496
497     /**
498         Get the first valid page. Result is latched.
499         @exception StandardException Standard Cloudscape error policy
500     */

501     protected Page getFirstPage(BaseContainerHandle handle) throws StandardException
502     {
503         return getFirstHeadPage(handle, true /* wait */);
504     }
505
506     /**
507         Get the next valid page and latch it
508         @exception StandardException Standard Cloudscape error policy
509     */

510     protected Page getNextPage(BaseContainerHandle handle, long pageNumber)
511         throws StandardException
512     {
513         return getNextHeadPage(handle, pageNumber, true /* wait */);
514     }
515
516     /*
517         utility to latch a page
518     */

519     protected BasePage latchPage(BaseContainerHandle handle, BasePage foundPage, boolean wait)
520          throws StandardException
521     {
522         if (foundPage != null) {
523              if (wait) {
524                 foundPage.setExclusive(handle);
525              } else {
526                  if (!foundPage.setExclusiveNoWait(handle))
527                  {
528                      // sub-class will release page from the cache if required.
529
return null;
530                  }
531              }
532         }
533
534         if (SanityManager.DEBUG) {
535             SanityManager.ASSERT((foundPage == null) || foundPage.isLatched());
536         }
537
538         return foundPage;
539
540     }
541
542
543     /**
544         Lock the container and mark the container as in-use by this container handle.
545
546         @param droppedOK if true, use this container even if it is dropped.,
547         @return true if the container can be used, false if it has been dropped
548         since the lock was requested and droppedOK is not true.
549
550         @exception StandardException I cannot be opened for update.
551     */

552     protected boolean use(BaseContainerHandle handle, boolean forUpdate,
553                           boolean droppedOK)
554         throws StandardException {
555
556         // see if the container can be updated
557
if (forUpdate && !canUpdate())
558         {
559             throw StandardException.newException(
560                     SQLState.DATA_CONTAINER_READ_ONLY);
561         }
562
563         // if the container is dropped, cannot see if unless droppedOK is set
564
if (!droppedOK && (getDroppedState() || getCommittedDropState())) {
565             return false;
566         }
567
568         return true;
569     }
570
571     /**
572         Discontinue use of this container. Note that the unlockContainer
573         call made from this method may not release any locks. The container
574         lock may be held until the end of the transaction.
575
576     */

577     protected void letGo(BaseContainerHandle handle) {
578
579         RawTransaction t = handle.getTransaction();
580
581         handle.getLockingPolicy().unlockContainer(t, handle);
582     }
583
584     protected boolean getDroppedState() {
585         return isDropped;
586     }
587
588     protected boolean getCommittedDropState()
589     {
590         return isCommittedDrop;
591     }
592
593
594     protected boolean isReusableRecordId()
595     {
596         return isReusableRecordId;
597     }
598
599     public int getContainerStatus()
600     {
601         if (getCommittedDropState())
602             return RawContainerHandle.COMMITTED_DROP;
603
604         if (getDroppedState())
605             return RawContainerHandle.DROPPED;
606
607         return RawContainerHandle.NORMAL;
608     }
609
610     public long getContainerId() {
611         return identity.getContainerId();
612     }
613
614     public long getSegmentId() {
615         return identity.getSegmentId();
616     }
617
618
619     //public int getPageSize() {
620
// return pageSize();
621
//}
622

623     /*
624     ** Methods that need to be provided by a sub-class.
625     */

626
627     /**
628     Get information about space used by the container.
629     **/

630     protected abstract SpaceInfo getSpaceInfo(BaseContainerHandle handle)
631         throws StandardException;
632
633     /**
634         Can the container be updated.
635
636         @return true if the container can be updated, false otherwise.
637     */

638     protected abstract boolean canUpdate();
639
640     /**
641         The container is about to be modified.
642         Loggable actions use this to make sure the container gets cleaned if a
643         checkpoint is taken after any log record is sent to the log stream but
644         before the container is actually dirtied.
645      */

646     protected abstract void preDirty(boolean preDirtyOn);
647
648
649     /**
650         Return a BasePage that represents the given page number in this container.
651         The resulting page is latched.
652
653         @exception StandardException Standard Cloudscape error policy
654     */

655     protected abstract BasePage getPage(BaseContainerHandle handle, long pageNumber,
656         boolean wait) throws StandardException;
657
658     /**
659         Return a BasePage that represents the given alloc page number in this container.
660
661         @exception StandardException Standard Cloudscape error policy
662     */

663     protected abstract BasePage getAllocPage(long pageNumber) throws StandardException;
664
665     /**
666         Return a BasePage that represents any page - alloc page, valid page, free page,
667         dealloced page etc. The only requirement is that the page is initialized...
668
669         @exception StandardException Cloudscape Standard error policy
670     */

671     protected abstract BasePage getAnyPage(BaseContainerHandle handle, long pageNumber)
672          throws StandardException;
673
674     /**
675      * ReCreate a page for rollforward recovery.
676      * <p>
677      * During redo recovery it is possible for the system to try to redo
678      * the creation of a page (ie. going from non-existence to version 0).
679      * It first trys to read the page from disk, but a few different types
680      * of errors can occur:
681      * o the page does not exist at all on disk, this can happen during
682      * rollforward recovery applied to a backup where the file was
683      * copied and the page was added to the file during the time frame
684      * of the backup but after the physical file was copied.
685      * o space in the file exists, but it was never initalized. This
686      * can happen if you happen to crash at just the right moment during
687      * the allocation process. Also
688      * on some OS's it is possible to read from a part of the file that
689      * was not ever written - resulting in garbage from the store's
690      * point of view (often the result is all 0's).
691      *
692      * All these errors are easy to recover from as the system can easily
693      * create a version 0 from scratch and write it to disk.
694      *
695      * Because the system does not sync allocation of data pages, it is also
696      * possible at this point that whlie writing the version 0 to disk to
697      * create it we may encounter an out of disk space error (caught in this
698      * routine as a StandardException from the create() call. We can't
699      * recovery from this without help from outside, so the caught exception
700      * is nested and a new exception thrown which the recovery system will
701      * output to the user asking them to check their disk for space/errors.
702      *
703      * The arguments passed in need to be sufficient for the page cache to
704      * materialize a brand new page and write it to disk.
705      *
706      * @exception StandardException Standard exception policy.
707      **/

708     protected abstract BasePage
709     reCreatePageForRedoRecovery(
710     BaseContainerHandle handle,
711     int pageFormat,
712     long pageNumber,
713     long pageOffset)
714          throws StandardException;
715
716     /**
717         Log all information on the container creation necessary to recreate teh
718         container during a load tran.
719
720         @exception StandardException Cloudscape Standard error policy
721      */

722      protected abstract ByteArray logCreateContainerInfo()
723          throws StandardException;
724
725
726     /**
727         Get only a valid, non-overflow page. If page number is either invalid
728         or overflow, returns null
729
730         @exception StandardException Cloudscape Standard error policy
731      */

732     protected abstract BasePage getHeadPage(BaseContainerHandle handle,
733         long pagenumber, boolean wait) throws StandardException;
734
735     /**
736         Get the first page in the container.
737         @exception StandardException Standard Cloudscape error policy
738     */

739     protected abstract BasePage getFirstHeadPage(BaseContainerHandle handle,
740         boolean wait) throws StandardException;
741
742     /**
743         Get the next page in the container.
744         @exception StandardException Standard Cloudscape error policy
745     */

746     protected abstract BasePage getNextHeadPage(BaseContainerHandle handle,
747         long pageNumber, boolean wait) throws StandardException;
748
749     /**
750         Get a potentially suitable page for insert and latch it.
751         @exception StandardException Standard Cloudscape error policy
752      */

753     protected abstract BasePage getPageForInsert(BaseContainerHandle handle,
754                                                  int flag)
755          throws StandardException;
756
757     protected abstract BasePage getPageForCompress(
758     BaseContainerHandle handle,
759     int flag,
760     long pageno)
761          throws StandardException;
762
763     protected abstract void truncatePages(long lastValidPagenum)
764         throws StandardException;
765
766
767     /**
768         Create a new page in the container.
769
770         @exception StandardException Standard Cloudscape error policy
771     */

772     protected abstract BasePage newPage(BaseContainerHandle userhandle,
773                                         RawTransaction t,
774                                         BaseContainerHandle allocHandle,
775                                         boolean isOverflow) throws StandardException;
776
777     protected abstract void compressContainer(
778     RawTransaction t,
779     BaseContainerHandle allocHandle)
780         throws StandardException;
781
782
783     /**
784         Deallocate a page from the container.
785
786         @exception StandardException Standard Cloudscape error policy
787     */

788     protected abstract void deallocatePage(BaseContainerHandle userhandle,
789                                            BasePage page) throws StandardException;
790
791
792     protected void truncate(BaseContainerHandle handle) throws StandardException {
793         if (SanityManager.DEBUG) {
794             SanityManager.THROWASSERT("truncate not supported");
795         }
796     }
797
798     /**
799         Mark the container as drop or not drop depending on the input value.
800
801     */

802     protected abstract void dropContainer(LogInstant instant, boolean drop);
803
804
805     /**
806         Remove the container and reclaim its space. Once executed, this
807         operation cannot be undone - as opposed to dropContainer which only
808         marks the container as dropped and can be rolled back.
809         <BR><B> This operation should only be called by post commit clean up </B>
810
811         @param leaveStub if true, leave a stub. If false, remove everything
812         @see org.apache.derby.iapi.store.raw.data.RawContainerHandle#removeContainer
813
814         @exception StandardException Standard Cloudscape error policy
815     */

816     protected abstract void removeContainer(LogInstant instant, boolean leaveStub) throws StandardException;
817
818     /**
819         Get the logged container version.
820
821         @exception StandardException Standard Cloudscape error policy
822     */

823     protected abstract long getContainerVersion() throws StandardException;
824
825     /**
826         Flush all outstanding changes in this container to persistent storage.
827
828         @exception StandardException Standard Cloudscape error policy
829     */

830     protected abstract void flushAll() throws StandardException;
831
832     /**
833         The container will be grown vastly, prepare for it.
834     */

835     protected abstract void prepareForBulkLoad(BaseContainerHandle handle,
836                                                int numPage);
837
838     /**
839         The container will have no pre-allocate threshold, i.e., if the
840         implementation supports it, page preallocation will happen
841         the next time a new page is allocated.
842     */

843     protected abstract void clearPreallocThreshold();
844
845     /*
846         Cost estimates
847     */

848     /**
849         @see ContainerHandle#getEstimatedRowCount
850         @exception StandardException Standard Cloudscape error policy
851      */

852     public abstract long getEstimatedRowCount(int flag) throws StandardException;
853
854     /**
855         @see ContainerHandle#setEstimatedRowCount
856         @exception StandardException Standard Cloudscape error policy
857      */

858     public abstract void setEstimatedRowCount(long count, int flag) throws StandardException;
859
860     /**
861         @see ContainerHandle#getEstimatedPageCount
862         @exception StandardException Standard Cloudscape error policy
863      */

864     public abstract long getEstimatedPageCount(BaseContainerHandle handle, int flag) throws StandardException;
865
866     /**
867      * Backup the container to the specified path.
868      *
869      * @param handle the container handle.
870      * @param backupContainerPath location of the backup container.
871      * @exception StandardException Standard Derby error policy
872      */

873     protected abstract void backupContainer(BaseContainerHandle handle,
874                                              String JavaDoc backupContainerPath) throws StandardException ;
875
876
877     /**
878      * Create encrypted version of the container with the
879      * user specified encryption properties.
880      *
881      * @param handle the container handle.
882      * @param newFilePath file to store the new encrypted version of the container
883      * @exception StandardException Standard Derby error policy
884      */

885     protected abstract void encryptContainer(BaseContainerHandle handle,
886                                               String JavaDoc newFilePath)
887         throws StandardException ;
888
889
890     /*
891     ** Methods to be used by sub-classes.
892     */

893
894     /**
895         Set the container's dropped state
896     */

897     protected void setDroppedState(boolean isDropped) {
898         this.isDropped = isDropped;
899     }
900
901     protected void setCommittedDropState(boolean isCommittedDrop)
902     {
903         this.isCommittedDrop = isCommittedDrop;
904     }
905
906
907     protected void setReusableRecordIdState(boolean isReusableRecordId)
908     {
909         this.isReusableRecordId = isReusableRecordId;
910     }
911
912     //protected void setPageSize(int pageSize) {
913
// identity.setPageSize(pageSize);
914
//}
915

916     // Not interested in participating in the diagnostic virtual lock table.
917
public boolean lockAttributes(int flag, Hashtable JavaDoc attributes)
918     {
919         return false;
920     }
921
922     
923
924 }
925
926
Popular Tags