KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > access > sort > MergeSortInfo


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.sort.MergeSortInfo
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.access.sort;
23
24 import org.apache.derby.iapi.store.access.SortInfo;
25
26 import org.apache.derby.iapi.error.StandardException;
27
28 import org.apache.derby.iapi.reference.SQLState;
29
30 import org.apache.derby.iapi.services.i18n.MessageService;
31
32 import java.util.Vector JavaDoc;
33 import java.util.Properties JavaDoc;
34
35 /**
36
37   This object provides performance information related to a sort.
38   The information is accumulated during operations on a SortController() and
39   then copied into this object and returned by a call to
40   SortController.getSortInfo().
41
42   @see org.apache.derby.iapi.store.access.SortController#getSortInfo()
43
44 **/

45 class MergeSortInfo implements SortInfo
46 {
47     /**
48      * Performance counters ...
49      */

50
51     private String JavaDoc stat_sortType;
52     // private long stat_estimMemUsed;
53
private int stat_numRowsInput;
54     private int stat_numRowsOutput;
55     private int stat_numMergeRuns;
56     private Vector JavaDoc stat_mergeRunsSize;
57
58
59     /* Constructors for This class: */
60     MergeSortInfo(MergeInserter sort)
61     {
62         // copy perfomance state out of sort, to get a fixed set of stats
63
stat_sortType = sort.stat_sortType;
64         // stat_estimMemUsed = sort.estimatedMemoryUsed;
65
stat_numRowsInput = sort.stat_numRowsInput;
66         stat_numRowsOutput = sort.stat_numRowsOutput;
67         stat_numMergeRuns = sort.stat_numMergeRuns;
68         stat_mergeRunsSize = sort.stat_mergeRunsSize;
69     }
70
71     /**
72      * Return all information gathered about the sort.
73      * <p>
74      * This routine returns a list of properties which contains all information
75      * gathered about the sort. If a Property is passed in, then that property
76      * list is appended to, otherwise a new property object is created and
77      * returned.
78      * <p>
79      * Not all sorts may support all properties, if the property is not
80      * supported then it will not be returned. The following is a list of
81      * properties that may be returned:
82      *
83      * sortType
84      * - type of the sort being performed:
85      * internal
86      * external
87      * numRowsInput
88      * - the number of rows input to the sort. This
89      * number includes duplicates.
90      * numRowsOutput
91      * - the number of rows to be output by the sort. This number
92      * may be different from numRowsInput since duplicates may not
93      * be output.
94      * numMergeRuns
95      * - the number of merge runs for the sort.
96      * Applicable to external sorts only.
97      * Note: when a SortController is closed, numMergeRuns may increase by 1, to
98      * reflect the additional merge run that may be created for
99      * any data still in the sort buffer.
100      * mergeRunsSize
101      * - the size (number of rows) of each merge run for the sort.
102      * Applicable to external sorts only.
103      * e.g. [3,3,2] indicates 3 merge runs, where the first two runs
104      * have 3 rows each, and the last run has 2 rows.
105      * Note: when a SortController is closed, this vector may get an
106      * additional element, to reflect the additional merge run that
107      * may be created for any data still in the sort buffer.
108      * NOTE - this list will be expanded as more information about the sort
109      * is gathered and returned.
110      *
111      * @param prop Property list to fill in.
112      *
113      * @exception StandardException Standard exception policy.
114      **/

115
116     public Properties JavaDoc getAllSortInfo(Properties JavaDoc prop)
117         throws StandardException
118     {
119         if (prop == null)
120             prop = new Properties JavaDoc();
121
122         prop.put(
123             MessageService.getTextMessage(SQLState.STORE_RTS_SORT_TYPE),
124             "external".equals(this.stat_sortType) ?
125                 MessageService.getTextMessage(SQLState.STORE_RTS_EXTERNAL) :
126                 MessageService.getTextMessage(SQLState.STORE_RTS_INTERNAL));
127         // prop.put(
128
// MessageService.getTextMessage(SQLState.STORE_RTS_ESTIMATED_MEMORY_USED),
129
// Long.toString(stat_estimMemUsed));
130
prop.put(
131             MessageService.getTextMessage(SQLState.STORE_RTS_NUM_ROWS_INPUT),
132             Integer.toString(stat_numRowsInput));
133         prop.put(
134             MessageService.getTextMessage(SQLState.STORE_RTS_NUM_ROWS_OUTPUT),
135             Integer.toString(stat_numRowsOutput));
136         if (this.stat_sortType == "external")
137         {
138             prop.put(
139               MessageService.getTextMessage(SQLState.STORE_RTS_NUM_MERGE_RUNS),
140               Integer.toString(stat_numMergeRuns));
141             prop.put(
142               MessageService.getTextMessage(SQLState.STORE_RTS_MERGE_RUNS_SIZE),
143               stat_mergeRunsSize.toString());
144         }
145         return(prop);
146     }
147 }
148
149
150     /**
151      * estimMemUsed IS NOT CURRENTLY SUPPORTED SINCE IT IS UNRELIABLE
152      * estimMemUsed
153      * - the estimated memory used by the sort.
154      *
155      * This is only measured when the system runs out of sort
156      * buffer space, AND when it tries to avoid doing an external sort.
157      * It measures this by subtracting the memory usage at initialization
158      * from the memory usage at the time we are trying to avoid doing an
159      * external sort. The result could be negative: this probably indicates
160      * that there has been some garbage collection in the interim.
161      * If the attempt at keeping the sort internal succeeds, the buffer grows
162      * but the increased memory usage is not measured.
163      *
164      * The system may never measure the memory usage. This happens if
165      * it never runs out of sort buffer space, or if it is set up not
166      * to avoid external sorts. In cases that it is not measured, it returns 0.
167      *
168      * In future, this info may improve with an improved JVM API.
169      */

170
171
Popular Tags