⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d_btreecontroller.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*   Derby - Class org.apache.derby.impl.store.access.btree.D_BTreeController   Copyright 1998, 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;import org.apache.derby.iapi.reference.Property;import org.apache.derby.iapi.services.context.ContextManager;import org.apache.derby.iapi.services.diag.Diagnosticable;import org.apache.derby.iapi.services.diag.DiagnosticableGeneric;import org.apache.derby.iapi.services.diag.DiagnosticUtil;import org.apache.derby.iapi.services.monitor.Monitor;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.db.Database;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.store.access.AccessFactory;import org.apache.derby.iapi.store.access.ConglomerateController;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.store.raw.ContainerHandle;import org.apache.derby.iapi.store.raw.Page;import java.util.Properties;/**  A BTreeDiag class is a "helper" class for the rest of the btree generic  code.  It is separated into a separate class so that it can be compiled  out if necessary (or loaded at runtime if necessary).  <p>  more info.**/class LevelInfo{    public int num_pages          = 0; // number of pages in heap.    public int num_overflow_pgs   = 0; // number of overflow pages heap.    public int num_entries        = 0; // number recs on page    public int num_deleted        = 0; // number of recs on page marked deleted.    public long max_pageno        = 0; // biggest page number allocated    public long num_free_bytes    = 0; // number of free bytes on the pages.    public long num_res_bytes     = 0; // number of reserved bytes on the pages.    public long num_overflow_rows = 0; // number of over flow rows on page.    public long num_rowsize_bytes = 0; // number of bytes in rows.    public long num_slottab_bytes = 0; // number of bytes in slot table.    public long min_rowsize_bytes = Long.MAX_VALUE; // length of shortest row.    public long max_rowsize_bytes = Long.MIN_VALUE; // length of longest row.}public class D_BTreeController extends DiagnosticableGeneric{    /* Private/Protected methods of This class: */    private static void diag_page(    OpenBTree   open_btree,    ControlRow  control_row,     Properties  prop,    LevelInfo   level_info[])        throws StandardException    {        LevelInfo li    = level_info[control_row.getLevel()];        Page      page  = control_row.page;        li.num_pages++;        li.num_entries += (page.recordCount() - 1);        li.num_deleted += (page.recordCount() - page.nonDeletedRecordCount());        li.max_pageno  = Math.max(li.max_pageno, page.getPageNumber());        DiagnosticUtil.findDiagnostic(page).diag_detail(prop);        DiagnosticUtil.findDiagnostic(page).diag_detail(prop);        // number of free bytes on page.        int free_bytes =             Integer.parseInt(prop.getProperty(Page.DIAG_BYTES_FREE));        li.num_free_bytes += free_bytes;        // number of bytes reserved on page.        int res_bytes =             Integer.parseInt(prop.getProperty(Page.DIAG_BYTES_RESERVED));        li.num_res_bytes += res_bytes;        // overflow rows.        int overflow =             Integer.parseInt(prop.getProperty(Page.DIAG_NUMOVERFLOWED));        li.num_overflow_rows += overflow;        // size of rows.        int rowsize =             Integer.parseInt(prop.getProperty(Page.DIAG_ROWSIZE));        li.num_rowsize_bytes += rowsize;        // size of slot table.        int slottable_size =             Integer.parseInt(prop.getProperty(Page.DIAG_SLOTTABLE_SIZE));        li.num_slottab_bytes += slottable_size;        // minimum row size.        int min_rowsize =             Integer.parseInt(prop.getProperty(Page.DIAG_MINROWSIZE));        li.min_rowsize_bytes = Math.min(li.min_rowsize_bytes, min_rowsize);        // maximum row size.        int max_rowsize =             Integer.parseInt(prop.getProperty(Page.DIAG_MAXROWSIZE));        li.max_rowsize_bytes = Math.max(li.max_rowsize_bytes, max_rowsize);    }    private static void diag_level(    OpenBTree   open_btree,    ControlRow  control_row,     Properties  prop,    LevelInfo   level_info[])        throws StandardException    {        ControlRow      child = null;        diag_page(open_btree, control_row, prop, level_info);        try        {            child = control_row.getLeftChild(open_btree);            if (child != null)            {                // this is a branch page.                if (SanityManager.DEBUG)                    SanityManager.ASSERT(                        control_row instanceof BranchControlRow);                BranchControlRow branch = (BranchControlRow) control_row;                diag_level(open_btree, child, prop, level_info);                child.release();                child = null;                int numslots = branch.page.recordCount();                for (int slot = 1; slot < numslots; slot++)                {                    child = branch.getChildPageAtSlot(open_btree, slot);                    diag_level(open_btree, child, prop, level_info);                    child.release();                    child = null;                }            }        }        finally        {            if (child != null)                child.release();        }        return;    }    private static String out_summary(    String  hdr,    long    value,    double  ratio,    String  ratio_desc)    {        String double_str = "" + ratio;        String short_str = double_str.substring(            0, Math.min(double_str.lastIndexOf(".") + 3, double_str.length()));        return(            "\t" + hdr + value + ".\t(" + short_str +             " " + ratio_desc + ").\n");    }    private static String diag_onelevel(    Properties  prop,    LevelInfo   li)    {        String ret_string   = new String();        ret_string +=             "Btree conglom has:\n" +             "\t" + prop.getProperty(Page.DIAG_PAGE_SIZE) + " bytes per page\n" +            "\t" + li.num_pages           + " total used pages (" +                (Integer.parseInt(prop.getProperty(Page.DIAG_PAGE_SIZE)) *                      li.num_pages) +                 " bytes)\n"            +            "\tmaximum page number   = " + li.max_pageno + ".\n"         +            "\treserved space %      = " + prop.getProperty(Page.DIAG_RESERVED_SPACE) + "%.\n"         +            "\tminimum record size   = " + prop.getProperty(Page.DIAG_MINIMUM_REC_SIZE) + ".\n"         +            "\tpage overhead bytes   = " + prop.getProperty(Page.DIAG_PAGEOVERHEAD) + " bytes per page.\n"         +            "\tminimum record length = " + li.min_rowsize_bytes + ".\n" +            "\tmaximum record length = " + li.max_rowsize_bytes + ".\n" +            "\t# of bytes in rows    = " + li.num_rowsize_bytes + "." +                "\t(" +                 (li.num_entries == 0 ?                      0 : (li.num_rowsize_bytes / li.num_entries)) +                 " bytes/row).\n"                                  +            out_summary(                "# of reserved bytes   = ",                 li.num_res_bytes,                (li.num_res_bytes / li.num_pages),

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -