|
27 | 27 | import java.util.Map; |
28 | 28 |
|
29 | 29 | /** |
30 | | - * |
| 30 | + * An interface for managing a repository of blob entries, where each blob entry is just a named group of bytes. |
31 | 31 | */ |
32 | 32 | public interface BlobContainer { |
33 | 33 |
|
| 34 | + /** |
| 35 | + * Gets the {@link BlobPath} that defines the implementation specific paths to where the blobs are contained. |
| 36 | + * |
| 37 | + * @return the BlobPath where the blobs are contained |
| 38 | + */ |
34 | 39 | BlobPath path(); |
35 | 40 |
|
| 41 | + /** |
| 42 | + * Tests whether a blob with the given blob name exists in the container. |
| 43 | + * |
| 44 | + * @param blobName |
| 45 | + * The name of the blob whose existence is to be determined. |
| 46 | + * @return {@code true} if a blob exists in the {@link BlobContainer} with the given name, and {@code false} otherwise. |
| 47 | + * @throws IOException if any error occurred while attempting to ascertain if the blob exists |
| 48 | + */ |
36 | 49 | boolean blobExists(String blobName); |
37 | 50 |
|
38 | 51 | /** |
39 | | - * Creates a new InputStream for the given blob name |
| 52 | + * Creates a new {@link InputStream} for the given blob name. |
| 53 | + * |
| 54 | + * @param blobName |
| 55 | + * The name of the blob to get an {@link InputStream} for. |
| 56 | + * @return The {@code InputStream} to read the blob. |
| 57 | + * @throws IOException if the blob does not exist or can not be read. |
40 | 58 | */ |
41 | 59 | InputStream readBlob(String blobName) throws IOException; |
42 | 60 |
|
43 | 61 | /** |
44 | | - * Reads blob content from the input stream and writes it to the blob store |
| 62 | + * Reads blob content from the input stream and writes it to the container in a new blob with the given name. |
| 63 | + * This method assumes the container does not already contain a blob of the same blobName. If a blob by the |
| 64 | + * same name already exists, the operation will fail and an {@link IOException} will be thrown. |
| 65 | + * |
| 66 | + * @param blobName |
| 67 | + * The name of the blob to write the contents of the input stream to. |
| 68 | + * @param inputStream |
| 69 | + * The input stream from which to retrieve the bytes to write to the blob. |
| 70 | + * @param blobSize |
| 71 | + * The size of the blob to be written, in bytes. It is implementation dependent whether |
| 72 | + * this value is used in writing the blob to the repository. |
| 73 | + * @throws IOException if the input stream could not be read, a blob by the same name already exists, |
| 74 | + * or the target blob could not be written to. |
45 | 75 | */ |
46 | 76 | void writeBlob(String blobName, InputStream inputStream, long blobSize) throws IOException; |
47 | 77 |
|
48 | 78 | /** |
49 | | - * Writes bytes to the blob |
| 79 | + * Writes the input bytes to a new blob in the container with the given name. This method assumes the |
| 80 | + * container does not already contain a blob of the same blobName. If a blob by the same name already |
| 81 | + * exists, the operation will fail and an {@link IOException} will be thrown. |
| 82 | + * |
| 83 | + * TODO: Remove this in favor of a single {@link #writeBlob(String, InputStream, long)} method. |
| 84 | + * See https://github.com/elastic/elasticsearch/issues/18528 |
| 85 | + * |
| 86 | + * @param blobName |
| 87 | + * The name of the blob to write the contents of the input stream to. |
| 88 | + * @param bytes |
| 89 | + * The bytes to write to the blob. |
| 90 | + * @throws IOException if a blob by the same name already exists, or the target blob could not be written to. |
50 | 91 | */ |
51 | 92 | void writeBlob(String blobName, BytesReference bytes) throws IOException; |
52 | 93 |
|
53 | 94 | /** |
54 | | - * Deletes a blob with giving name. |
| 95 | + * Deletes a blob with giving name, if the blob exists. If the blob does not exist, this method throws an IOException. |
55 | 96 | * |
56 | | - * If a blob exists but cannot be deleted an exception has to be thrown. |
| 97 | + * @param blobName |
| 98 | + * The name of the blob to delete. |
| 99 | + * @throws IOException if the blob does not exist, or if the blob exists but could not be deleted. |
57 | 100 | */ |
58 | 101 | void deleteBlob(String blobName) throws IOException; |
59 | 102 |
|
60 | 103 | /** |
61 | | - * Deletes blobs with giving names. |
| 104 | + * Deletes blobs with the given names. If any subset of the names do not exist in the container, this method has no |
| 105 | + * effect for those names, and will delete the blobs for those names that do exist. If any of the blobs failed |
| 106 | + * to delete, those blobs that were processed before it and successfully deleted will remain deleted. An exception |
| 107 | + * is thrown at the first blob entry that fails to delete (TODO: is this the right behavior? Should we collect |
| 108 | + * all the failed deletes into a single IOException instead?) |
62 | 109 | * |
63 | | - * If a blob exists but cannot be deleted an exception has to be thrown. |
| 110 | + * TODO: remove, see https://github.com/elastic/elasticsearch/issues/18529 |
| 111 | + * |
| 112 | + * @param blobNames |
| 113 | + * The collection of blob names to delete from the container. |
| 114 | + * @throws IOException if any of the blobs in the collection exists but could not be deleted. |
64 | 115 | */ |
65 | 116 | void deleteBlobs(Collection<String> blobNames) throws IOException; |
66 | 117 |
|
67 | 118 | /** |
68 | | - * Deletes all blobs in the container that match the specified prefix. |
| 119 | + * Deletes all blobs in the container that match the specified prefix. If any of the blobs failed to delete, |
| 120 | + * those blobs that were processed before it and successfully deleted will remain deleted. An exception is |
| 121 | + * thrown at the first blob entry that fails to delete (TODO: is this the right behavior? Should we collect |
| 122 | + * all the failed deletes into a single IOException instead?) |
| 123 | + * |
| 124 | + * TODO: remove, see: https://github.com/elastic/elasticsearch/issues/18529 |
| 125 | + * |
| 126 | + * @param blobNamePrefix |
| 127 | + * The prefix to match against blob names in the container. Any blob whose name has the prefix will be deleted. |
| 128 | + * @throws IOException if any of the matching blobs failed to delete. |
69 | 129 | */ |
70 | 130 | void deleteBlobsByPrefix(String blobNamePrefix) throws IOException; |
71 | 131 |
|
72 | 132 | /** |
73 | | - * Lists all blobs in the container |
| 133 | + * Lists all blobs in the container. |
| 134 | + * |
| 135 | + * @return A map of all the blobs in the container. The keys in the map are the names of the blobs and |
| 136 | + * the values are {@link BlobMetaData}, containing basic information about each blob. |
| 137 | + * @throws IOException if there were any failures in reading from the blob container. |
74 | 138 | */ |
75 | 139 | Map<String, BlobMetaData> listBlobs() throws IOException; |
76 | 140 |
|
77 | 141 | /** |
78 | | - * Lists all blobs in the container that match specified prefix |
| 142 | + * Lists all blobs in the container that match the specified prefix. |
| 143 | + * |
| 144 | + * @param blobNamePrefix |
| 145 | + * The prefix to match against blob names in the container. |
| 146 | + * @return A map of the matching blobs in the container. The keys in the map are the names of the blobs |
| 147 | + * and the values are {@link BlobMetaData}, containing basic information about each blob. |
| 148 | + * @throws IOException if there were any failures in reading from the blob container. |
79 | 149 | */ |
80 | 150 | Map<String, BlobMetaData> listBlobsByPrefix(String blobNamePrefix) throws IOException; |
81 | 151 |
|
82 | 152 | /** |
83 | | - * Atomically renames source blob into target blob |
| 153 | + * Atomically renames the source blob into the target blob. If the source blob does not exist or the |
| 154 | + * target blob already exists, an exception is thrown. |
| 155 | + * |
| 156 | + * @param sourceBlobName |
| 157 | + * The blob to rename. |
| 158 | + * @param targetBlobName |
| 159 | + * The name of the blob after the renaming. |
| 160 | + * @throws IOException if the source blob does not exist, the target blob already exists, |
| 161 | + * or there were any failures in reading from the blob container. |
84 | 162 | */ |
85 | 163 | void move(String sourceBlobName, String targetBlobName) throws IOException; |
86 | 164 | } |
0 commit comments