📄 b2i.java
字号:
/* Derby - Class org.apache.derby.impl.store.access.btree.index.B2I Copyright 1997, 2004 The Apache Software Foundation or its licensors, as applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package org.apache.derby.impl.store.access.btree.index;import java.io.ObjectOutput;import java.io.ObjectInput;import java.io.IOException;import java.util.Properties;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.services.io.ArrayInputStream;import org.apache.derby.iapi.services.io.FormatableBitSet;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.store.access.conglomerate.Conglomerate;import org.apache.derby.iapi.store.access.conglomerate.LogicalUndo;import org.apache.derby.iapi.store.access.conglomerate.ScanManager;import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;import org.apache.derby.iapi.store.access.ConglomerateController;import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;import org.apache.derby.iapi.store.access.Qualifier;import org.apache.derby.iapi.types.RowLocation;import org.apache.derby.iapi.store.access.RowLocationRetRowSource;import org.apache.derby.iapi.store.access.ScanController;import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;import org.apache.derby.iapi.store.access.StoreCostController;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.store.access.ColumnOrdering;import org.apache.derby.iapi.services.io.FormatIdUtil;import org.apache.derby.iapi.services.io.StoredFormatIds;import org.apache.derby.iapi.store.raw.ContainerHandle;import org.apache.derby.iapi.store.raw.LockingPolicy;import org.apache.derby.iapi.store.raw.Page;import org.apache.derby.iapi.store.raw.RecordHandle;import org.apache.derby.iapi.store.raw.Transaction;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.impl.store.access.btree.BTree;import org.apache.derby.impl.store.access.btree.BTreeLockingPolicy;import org.apache.derby.impl.store.access.btree.LeafControlRow;import org.apache.derby.impl.store.access.btree.ControlRow;import org.apache.derby.impl.store.access.btree.OpenBTree;import org.apache.derby.impl.store.access.btree.WaitError;import org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil;import org.apache.derby.iapi.services.io.FormatableBitSet;import org.apache.derby.iapi.services.cache.ClassSize;/* * @format_id ACCESS_B2I_V1_ID * * @purpose The tag that describes the on disk representation of the B2I * conglomerate object. The B2I conglomerate object is stored in * a field of a row in the Conglomerate directory. * * @upgrade This format was made obsolete in the kimono release. * * @disk_layout * containerid(long) * segmentid(int) * number_of_key_fields(int) * number_of_unique_columns(int) * allow_duplicates(boolean) * maintain_parent_links(boolean) * format_of_this_conlgomerate(byte[]) * array_of_format_ids(byte[][]) * baseConglomerateId(long) * rowLocationColumn(int) *//* * @format_id ACCESS_B2I_V2_ID * * @purpose The tag that describes the on disk representation of the B2I * conglomerate object. The B2I conglomerate object is stored in * a field of a row in the Conglomerate directory. * * @upgrade The format id of this object is currently always read from disk * as a separate column in the conglomerate directory. To read * A conglomerate object from disk and upgrade it to the current * version do the following: * * format_id = get format id from a separate column * Upgradable conglom_obj = instantiate empty obj(format_id) * read in conglom_obj from disk * conglom = conglom_obj.upgradeToCurrent(); * * @disk_layout * format_of_this_conlgomerate(byte[]) * containerid(long) * segmentid(int) * number_of_key_fields(int) * number_of_unique_columns(int) * allow_duplicates(boolean) * maintain_parent_links(boolean) * array_of_format_ids(byte[][]) * baseConglomerateId(long) * rowLocationColumn(int) *//** * Implements an instance of a B-Tree secondary index conglomerate. * A B2I object has two roles. * <ol> * <li> * The B2I object is stored on disk, and holds the store specific * information needed to access/describe the conglomerate. This * includes information such as the format ids of the columns, * the conglomerate id of the base table, the location of * row location column. * </li> * <li> * Access to all the interfaces start by making a call off the * Conglomerate interface. So for instance to get a scan on the * conglomerate method {@link #openScan openScan} should be called. * </li> * </ol> */public class B2I extends BTree{ public static final String PROPERTY_BASECONGLOMID = "baseConglomerateId"; public static final String PROPERTY_ROWLOCCOLUMN = "rowLocationColumn"; public static final int FORMAT_NUMBER = StoredFormatIds.ACCESS_B2I_V3_ID; /* ** Fields of B2I. */ /** The id of the conglomerate which contains the base table. Row locations inserted into this secondary index are assumed to refer to that conglomerate. Used to obtain table/row locks on the base table rows which the index rows point at. **/ protected long baseConglomerateId; /** The column id (zero-based integer index) of the column which holds the row location to the base conglomerate. The default value of RowLocationColumn is the last key column. Used to obtain table/row locks on the base table rows with the index rows point at. Currently, RowLocationColumn must be the last key column. **/ protected int rowLocationColumn; private static final int BASE_MEMORY_USAGE = ClassSize.estimateBaseFromCatalog( B2I.class); public int estimateMemoryUsage() { return BASE_MEMORY_USAGE; } /************************************************************************** * Constructors for This class: ************************************************************************** */ /************************************************************************** * Protected locking implmentations of abtract BTree routines: * getBtreeLockingPolicy * lockTable ************************************************************************** */ /** * Create a new btree locking policy from scratch. * * @exception StandardException Standard exception policy. **/ protected BTreeLockingPolicy getBtreeLockingPolicy( Transaction rawtran, int lock_level, int mode, int isolation_level, ConglomerateController base_cc, OpenBTree open_btree) throws StandardException { BTreeLockingPolicy ret_locking_policy = null; if (SanityManager.DEBUG) { SanityManager.ASSERT( (isolation_level == TransactionController.ISOLATION_SERIALIZABLE) || (isolation_level == TransactionController.ISOLATION_REPEATABLE_READ) || (isolation_level == TransactionController.ISOLATION_READ_COMMITTED_NOHOLDLOCK) || (isolation_level == TransactionController.ISOLATION_READ_COMMITTED) || (isolation_level == TransactionController.ISOLATION_READ_UNCOMMITTED), "bad isolation_level = " + isolation_level); } if (lock_level == TransactionController.MODE_TABLE) { ret_locking_policy = new B2ITableLocking3( rawtran, lock_level, rawtran.newLockingPolicy( LockingPolicy.MODE_CONTAINER, isolation_level, true), base_cc, open_btree); } else if (lock_level == TransactionController.MODE_RECORD) { if (isolation_level == TransactionController.ISOLATION_SERIALIZABLE) { ret_locking_policy = new B2IRowLocking3( rawtran, lock_level, rawtran.newLockingPolicy( LockingPolicy.MODE_RECORD, isolation_level, true), base_cc, open_btree); } else if ((isolation_level == TransactionController.ISOLATION_REPEATABLE_READ)) { ret_locking_policy = new B2IRowLockingRR( rawtran, lock_level, rawtran.newLockingPolicy( LockingPolicy.MODE_RECORD, isolation_level, true), base_cc, open_btree); } else if ((isolation_level == TransactionController.ISOLATION_READ_COMMITTED) || (isolation_level == TransactionController.ISOLATION_READ_COMMITTED_NOHOLDLOCK)) { ret_locking_policy = new B2IRowLocking2( rawtran, lock_level, rawtran.newLockingPolicy( LockingPolicy.MODE_RECORD, isolation_level, true), base_cc, open_btree); } else if (isolation_level == TransactionController.ISOLATION_READ_UNCOMMITTED) { ret_locking_policy = new B2IRowLocking1( rawtran, lock_level, rawtran.newLockingPolicy( LockingPolicy.MODE_RECORD, isolation_level, true), base_cc, open_btree); } } if (SanityManager.DEBUG) { SanityManager.ASSERT( ret_locking_policy != null, "ret_locking_policy == null"); } return(ret_locking_policy); } /** * Lock the base table. * <p> * Assumes that segment of the base container is the same as the segment * of the btree segment. * <p> * RESOLVE - we really want to get the lock without opening the container. * raw store will be providing this. * * @param xact_manager Transaction to associate the lock with. * * @exception StandardException Standard exception policy. **/ public final ConglomerateController lockTable( TransactionManager xact_manager, int open_mode, int lock_level, int isolation_level) throws StandardException { open_mode |= TransactionController.OPENMODE_FOR_LOCK_ONLY; // open the base conglomerate - just to get the table lock. ConglomerateController cc = xact_manager.openConglomerate( this.baseConglomerateId, false, open_mode, lock_level, isolation_level); return(cc); } /************************************************************************** * Private methods of B2I, arranged alphabetically. ************************************************************************** */ private void traverseRight() { // RESOLVE - Do I have to do this??????????????? if (SanityManager.DEBUG) SanityManager.THROWASSERT("not implemented."); } /*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -