You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ChunkTable.java 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (C) 2011, Google Inc.
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.storage.dht.spi;
  44. import java.util.Collection;
  45. import java.util.Map;
  46. import java.util.Set;
  47. import org.eclipse.jgit.generated.storage.dht.proto.GitStore.ChunkMeta;
  48. import org.eclipse.jgit.storage.dht.AsyncCallback;
  49. import org.eclipse.jgit.storage.dht.ChunkKey;
  50. import org.eclipse.jgit.storage.dht.DhtException;
  51. import org.eclipse.jgit.storage.dht.PackChunk;
  52. import org.eclipse.jgit.storage.dht.StreamingCallback;
  53. /**
  54. * Stores object data in compressed pack format.
  55. * <p>
  56. * Each chunk stores multiple objects, using the highly compressed and Git
  57. * native pack file format. Chunks are sized during insertion, but average
  58. * around 1 MB for historical chunks, and may be as small as a few KB for very
  59. * recent chunks that were written in small bursts.
  60. * <p>
  61. * Objects whose compressed form is too large to fit into a single chunk are
  62. * fragmented across multiple chunks, and the fragment information is used to
  63. * put them back together in the correct order. Since the fragmenting occurs
  64. * after data compression, random access to bytes of the large object is not
  65. * currently possible.
  66. * <p>
  67. * Chunk keys are very well distributed, by embedding a uniformly random number
  68. * at the start of the key, and also including a small time component. This
  69. * layout permits chunks to be evenly spread across a cluster of disks or
  70. * servers in a round-robin fashion (based on a hash of the leading bytes), but
  71. * also offers some chance for older chunks to be located near each other and
  72. * have that part of the storage system see less activity over time.
  73. */
  74. public interface ChunkTable {
  75. /**
  76. * Asynchronously load one or more chunks
  77. * <p>
  78. * Callers are responsible for breaking up very large collections of chunk
  79. * keys into smaller units, based on the reader's batch size option. Since
  80. * chunks typically 1 MB each, 10-20 keys is a reasonable batch size, but
  81. * depends on available JVM memory and performance of this method obtaining
  82. * chunks from the database.
  83. *
  84. * @param options
  85. * options to control reading.
  86. * @param keys
  87. * the chunk keys to obtain.
  88. * @param callback
  89. * receives the results when ready. If this is an instance of
  90. * {@link StreamingCallback}, implementors should try to deliver
  91. * results early.
  92. */
  93. public void get(Context options, Set<ChunkKey> keys,
  94. AsyncCallback<Collection<PackChunk.Members>> callback);
  95. /**
  96. * Asynchronously load one or more chunk meta fields.
  97. * <p>
  98. * Usually meta is loaded by {@link #get(Context, Set, AsyncCallback)}, but
  99. * some uses may require looking up the fragment data without having the
  100. * entire chunk.
  101. *
  102. * @param options
  103. * options to control reading.
  104. * @param keys
  105. * the chunk keys to obtain.
  106. * @param callback
  107. * receives the results when ready. If this is an instance of
  108. * {@link StreamingCallback}, implementors should try to deliver
  109. * results early.
  110. */
  111. public void getMeta(Context options, Set<ChunkKey> keys,
  112. AsyncCallback<Map<ChunkKey, ChunkMeta>> callback);
  113. /**
  114. * Put some (or all) of a single chunk.
  115. * <p>
  116. * The higher level storage layer typically stores chunks in pieces. Its
  117. * common to first store the data, then much later store the fragments and
  118. * index. Sometimes all of the members are ready at once, and can be put
  119. * together as a single unit. This method handles both approaches to storing
  120. * a chunk.
  121. * <p>
  122. * Implementors must use a partial writing approach, for example:
  123. *
  124. * <pre>
  125. * ColumnUpdateList list = ...;
  126. * if (chunk.getChunkData() != null)
  127. * list.addColumn(&quot;chunk_data&quot;, chunk.getChunkData());
  128. * if (chunk.getChunkIndex() != null)
  129. * list.addColumn(&quot;chunk_index&quot;, chunk.getChunkIndex());
  130. * if (chunk.getFragments() != null)
  131. * list.addColumn(&quot;fragments&quot;, chunk.getFragments());
  132. * createOrUpdateRow(chunk.getChunkKey(), list);
  133. * </pre>
  134. *
  135. * @param chunk
  136. * description of the chunk to be stored.
  137. * @param buffer
  138. * buffer to enqueue the put onto.
  139. * @throws DhtException
  140. * if the buffer flushed and an enqueued operation failed.
  141. */
  142. public void put(PackChunk.Members chunk, WriteBuffer buffer)
  143. throws DhtException;
  144. /**
  145. * Completely remove a chunk and all of its data elements.
  146. * <p>
  147. * Chunk removal should occur as quickly as possible after the flush has
  148. * completed, as the caller has already ensured the chunk is not in use.
  149. *
  150. * @param key
  151. * key of the chunk to remove.
  152. * @param buffer
  153. * buffer to enqueue the remove onto.
  154. * @throws DhtException
  155. * if the buffer flushed and an enqueued operation failed.
  156. */
  157. public void remove(ChunkKey key, WriteBuffer buffer) throws DhtException;
  158. }