Merge lp:~pbeaman/akiban-persistit/allow-long-keys into lp:akiban-persistit

Proposed by Peter Beaman
Status: Merged
Approved by: Mike McMahon
Approved revision: 429
Merged at revision: 426
Proposed branch: lp:~pbeaman/akiban-persistit/allow-long-keys
Merge into: lp:akiban-persistit
Diff against target: 113 lines (+44/-8)
3 files modified
pom.xml (+1/-1)
src/main/java/com/persistit/Key.java (+38/-2)
src/main/java/com/persistit/TreeBuilder.java (+5/-5)
To merge this branch: bzr merge lp:~pbeaman/akiban-persistit/allow-long-keys
Reviewer Review Type Date Requested Status
Akiban Build User Needs Fixing
Nathan Williams Approve
Review via email: mp+154814@code.launchpad.net

Description of the change

Add constructor for com.persistit.Key that allows an oversized backing byte array. Such a Key can be passed to the Exchange#store method; it is the actual size of the encoded key, not the size of the backing byte array that is checked before an attempt to insert into the database.

The purpose of this is to allow akiban-server to manipulate large encoded key values using the native methods of the Key class. This constructor will probably otherwise be of limited value, but adding it does no real damage.

This proposal also increments the version number to 3.2.7 to be coordinated with the akiban-server dependency.

Finally, this branch also fixes a couple of Javadoc link errors.

To post a comment you must log in.
Revision history for this message
Nathan Williams (nwilliams) wrote :

As described.

review: Approve
Revision history for this message
Peter Beaman (pbeaman) wrote :

After the Approval I determined that the use case in Akiban Server is much cleaner with a different API. So the new 3-arg constructor has been removed and instead there is a new method setMaximumSize(size) that reallocates the backing byte array and clears the state.

I was going to make that an additional new proposal, but I guess my changes got added before the existing proposal was merged.

At any rate, the server version that will be proposed shortly depends on this new API.

Revision history for this message
Akiban Build User (build-akiban) wrote :

There was one failure during build/test:

* unknown exception (check log)

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pom.xml'
2--- pom.xml 2013-01-28 10:42:29 +0000
3+++ pom.xml 2013-03-21 22:40:25 +0000
4@@ -4,7 +4,7 @@
5
6 <groupId>com.akiban</groupId>
7 <artifactId>akiban-persistit</artifactId>
8- <version>3.2.6-SNAPSHOT</version>
9+ <version>3.2.7-SNAPSHOT</version>
10 <packaging>jar</packaging>
11
12 <parent>
13
14=== modified file 'src/main/java/com/persistit/Key.java'
15--- src/main/java/com/persistit/Key.java 2013-03-20 19:31:43 +0000
16+++ src/main/java/com/persistit/Key.java 2013-03-21 22:40:25 +0000
17@@ -451,6 +451,8 @@
18 */
19 public final static int MAX_KEY_LENGTH = 2047;
20
21+ public final static int MAX_KEY_LENGTH_UPPER_BOUND = 1024 * 1024 * 4;
22+
23 /**
24 * A <code>Key</code> segment value that collates before any actual key in a
25 * <code>Tree</code>. A <code>Key</code> may include an instance of this
26@@ -957,9 +959,11 @@
27 }
28
29 /**
30- * Construct a <code>Key</code> with the specified maximum length.
31+ * Construct a <code>Key</code> with the specified maximum length. The
32+ * specified length must be positive and less than or equal to
33+ * {@value #MAX_KEY_LENGTH}.
34 *
35- * @param Persistit
36+ * @param persistit
37 * the Persistit instance
38 * @param maxLength
39 * The maximum length
40@@ -1302,6 +1306,38 @@
41 return this;
42 }
43
44+ /**
45+ * <p>
46+ * Allocates a new backing byte array of the specified size. This method is
47+ * for specialized use cases in which it may be convenient to serialize long
48+ * values into a <code>Key</code> for purposes other than storing them in a
49+ * <code>Tree</code>. However, regardless of the size of the backing byte
50+ * array, an encoded key value larger than the architectural maximum size of
51+ * {@value #MAX_KEY_LENGTH} cannot be stored in a <code>Tree</code>.
52+ * </p>
53+ * <p>
54+ * The specified size must be between 0 and
55+ * {@value #MAX_KEY_LENGTH_UPPER_BOUND}. As a side-effect, this method also
56+ * calls the {@link #clear()} method.
57+ * </p>
58+ *
59+ * @param size
60+ * @throws IllegalArgumentException
61+ * if the specified size is not valid.
62+ */
63+ public void setMaximumSize(final int size) {
64+ clear();
65+ if (size <= 0) {
66+ throw new IllegalArgumentException("Key length must be positive:" + size);
67+ }
68+ if (size > MAX_KEY_LENGTH_UPPER_BOUND) {
69+ throw new IllegalArgumentException("Key length must be less than " + MAX_KEY_LENGTH_UPPER_BOUND + ": "
70+ + size);
71+ }
72+ _bytes = new byte[size + 1];
73+ _maxSize = size;
74+ }
75+
76 void clear(final boolean secure) {
77 if (secure) {
78 Util.clearBytes(_bytes, 0, _bytes.length);
79
80=== modified file 'src/main/java/com/persistit/TreeBuilder.java'
81--- src/main/java/com/persistit/TreeBuilder.java 2013-01-25 19:45:25 +0000
82+++ src/main/java/com/persistit/TreeBuilder.java 2013-03-21 22:40:25 +0000
83@@ -130,9 +130,9 @@
84 * per record while merging</li>
85 * <li>{@link #afterMergeKey(Exchange)} - customizable behavior after merging
86 * one record</li>
87- * <li>{@link #beforeSortVolumeClosed(Volume)} - customizable behavior before
88- * closing a sort volume when full</li>
89- * <li>{@link #afterSortVolumeClose(Volume)} - customizable behavior after
90+ * <li>{@link #beforeSortVolumeClosed(Volume, File)} - customizable behavior
91+ * before closing a sort volume when full</li>
92+ * <li>{@link #afterSortVolumeClose(Volume, File)} - customizable behavior after
93 * closing a sort volume when full</li>
94 * <li>{@link #getTreeComparator()} - return a custom Comparator to determine
95 * sequence in which trees are populated within the {@link #merge()} method
96@@ -461,7 +461,7 @@
97 /**
98 *
99 * @return List of directories set via the
100- * {@link #setSortFileDirectories(List)} method.
101+ * {@link #setSortTreeDirectories(List)} method.
102 */
103 public final List<File> getSortFileDirectories() {
104 return Collections.unmodifiableList(_directories);
105@@ -726,7 +726,7 @@
106 * This method may be extended to provide application-specific reporting
107 * functionality after a sort volume has been filled to capacity and has
108 * been evicted. An application may also modify the temporary directory set
109- * via {@link #setSortFileDirectories(List)} within this method if necessary
110+ * via {@link #setSortTreeDirectories(List)} within this method if necessary
111 * to adjust disk space utilization, for example. The default behavior of
112 * this method is to do nothing.
113 *

Subscribers

People subscribed via source and target branches