├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── pom.xml
└── src
├── main
├── assembly
│ └── jar-with-dependencies.xml
├── java
│ └── org
│ │ └── gaul
│ │ └── areweconsistentyet
│ │ ├── AreWeConsistentYet.java
│ │ └── Utils.java
└── resources
│ ├── checkstyle.xml
│ ├── copyright_header.txt
│ └── logback.xml
└── test
└── java
└── org
└── gaul
└── areweconsistentyet
└── AreWeConsistentYetTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - openjdk8
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Are We Consistent Yet?
2 |
3 | Observed and documented eventual consistency of object stores, e.g., Amazon S3,
4 | OpenStack Swift.
5 |
6 | ## What is eventual consistency?
7 |
8 | Traditional systems provide
9 | [strong consistency](https://en.wikipedia.org/wiki/Strong_consistency), where
10 | clients can immediately view updates.
11 | Some distributed systems relax their consistency model to allow greater
12 | availability or better performance.
13 | [Eventual consistency](https://en.wikipedia.org/wiki/Eventual_consistency)
14 | manifests itself to clients as stale views of data.
15 |
16 | ## Observed consistency
17 |
18 | We ran a test in which we wrote (i.e., create, update, delete) an object and
19 | then attempted to read the object. Across many trials, we count the number of
20 | times the object was not immediately available. When the object is not
21 | immediately found, it's an occurrence of observed eventual consistency.
22 |
23 | Observed instances of eventual consistency with a number of operations during
24 | tests around 17 December 2014 with a 1-byte object size:
25 |
26 | | Provider | read after create | read after delete | read after overwrite | list after create | list after delete | number of operations |
27 | | --- | :---: | :---: | :---: | :---: | :---: | :---: |
28 | | Amazon S3 (us-standard) | * | * | * | 16 | * | 100,000 |
29 | | Amazon S3 (us-standard†) | 16 | 8 | 12 | 8 | 3 | 1,000 |
30 | | Amazon S3 (us-west) | - | 1 | 1 | * | * | 100,000 |
31 | | Ceph (DreamObjects) | - | - | - | - | - | 1,000 |
32 | | Google Cloud Storage | - | - | - | 2 | 2 | 1,000 |
33 | | Microsoft Azure Storage | - | - | - | - | - | 1,000 |
34 | | OpenStack Swift (Rackspace) | - | 17 | 3 | 30 | 20 | 1,000 |
35 |
36 | Legend:
37 |
38 | * \- zero observed instances
39 | * \* zero observed instances but expect non-zero
40 | * † writing to N. Virginia and reading from Pacific Northwest
41 |
42 | ## Documented consistency
43 |
44 | * [Amazon S3](http://aws.amazon.com/s3/faqs/#What_data_consistency_model_does_Amazon_S3_employ) - buckets in the US Standard region provide eventual consistency. Buckets in all other regions provide read-after-write consistency for PUTs of new objects and eventual consistency for overwrite PUTs and DELETEs.
45 | * [Ceph](https://ceph.com/wp-content/uploads/2016/08/weil-rados-pdsw07.pdf) - provides well-defined safety semantics and strong consistency guarantees.
46 | * [Google Cloud Storage](https://cloud.google.com/storage/docs/concepts-techniques#consistency) - provides strong global consistency for all read-after-write, read-after-update, and read-after-delete operations, including both data and metadata. Bucket and object listing are also strongly consistent.
47 | * [Microsoft Azure Storage](http://azure.microsoft.com/blog/2014/09/08/managing-concurrency-in-microsoft-azure-storage-2/) - was designed to embrace a strong consistency model which guarantees that when the Storage service commits a data insert or update operation all further accesses to that data will see the latest update.
48 | * [OpenStack Swift](http://docs.openstack.org/developer/swift/overview_architecture.html#updaters) - For example, suppose a container server is under load and a new object is put in to the system. The object will be immediately available for reads as soon as the proxy server responds to the client with success. However, the container server did not update the object listing, and so the update would be queued for a later update. Container listings, therefore, may not immediately contain the object. [Additional reference](http://lists.openstack.org/pipermail/openstack-dev/2014-June/038881.html).
49 |
50 | ## References
51 |
52 | * [Apache jclouds](https://jclouds.apache.org/) - provides object storage support
53 | * [A Middleware Guaranteeing Client-Centric Consistency on Top of Eventually
54 | Consistent Datastores](http://www.aifb.kit.edu/images/4/44/Ic2e2013consistency.pdf)
55 | * [Benchmarking Eventual Consistency: Lessons Learned from Long-Term Experimental Studies](http://www.aifb.kit.edu/images/8/8d/Ic2e2014.pdf)
56 | * [Eventual Consistency: How soon is eventual?](https://www.aifb.kit.edu/images/1/17/How_soon_is_eventual.pdf)
57 | * [Eventual Consistency Today: Limitations, Extensions, and Beyond](https://queue.acm.org/detail.cfm?id=2462076)
58 | * [Probabilistically Bounded Staleness](http://pbs.cs.berkeley.edu/) - includes discussion of Riak and Cassandra
59 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | org.sonatype.oss
6 | oss-parent
7 | 7
8 |
9 |
10 | org.gaul
11 | are-we-consistent-yet
12 | 1.0.0-SNAPSHOT
13 | jar
14 |
15 | Are We Consistent Yet
16 | https://github.com/andrewgaul/are-we-consistent-yet
17 | Test eventually-consistent behavior of different object stores
18 |
19 |
20 |
21 | The Apache Software License, Version 2.0
22 | http://www.apache.org/licenses/LICENSE-2.0.txt
23 | repo
24 |
25 |
26 |
27 |
28 | scm:git:git@github.com:andrewgaul/are-we-consistent-yet.git
29 | scm:git:git@github.com:andrewgaul/are-we-consistent-yet.git
30 | git@github.com:andrewgaul/are-we-consistent-yet.git
31 |
32 |
33 |
34 |
35 | Andrew Gaul
36 | gaul
37 | andrew@gaul.org
38 |
39 |
40 |
41 |
42 |
43 |
44 | org.apache.maven.plugins
45 | maven-checkstyle-plugin
46 | 2.14
47 |
48 |
49 | check
50 | verify
51 |
52 | check
53 |
54 |
55 |
56 |
57 | src/main/resources/checkstyle.xml
58 | src/main/resources/copyright_header.txt
59 | true
60 | warning
61 |
62 |
63 |
64 | org.apache.maven.plugins
65 | maven-compiler-plugin
66 | 3.1
67 |
68 | 1.7
69 | 1.7
70 | true
71 | true
72 |
73 |
74 |
75 |
76 |
77 |
78 | org.apache.maven.plugins
79 | maven-assembly-plugin
80 | 2.5.3
81 |
82 |
83 | src/main/assembly/jar-with-dependencies.xml
84 |
85 |
86 |
87 | org.gaul.areweconsistentyet.AreWeConsistentYet
88 | true
89 |
90 |
91 |
92 |
93 |
94 | make-assembly
95 | package
96 |
97 | single
98 |
99 |
100 |
101 |
102 |
103 | org.apache.maven.plugins
104 | maven-surefire-plugin
105 | 2.18.1
106 |
107 | classes
108 | 1
109 | -Xmx256m
110 | true
111 | 300
112 |
113 |
114 |
115 | org.codehaus.mojo
116 | findbugs-maven-plugin
117 | 3.0.0
118 |
119 | Max
120 | CrossSiteScripting
121 |
122 |
123 |
124 | org.skife.maven
125 | really-executable-jar-maven-plugin
126 | 1.4.0
127 |
128 | are-we-consistent-yet
129 |
130 |
131 |
132 | package
133 |
134 | really-executable-jar
135 |
136 |
137 |
138 |
139 |
140 | org.gaul
141 | modernizer-maven-plugin
142 | 1.3.0
143 |
144 |
145 | modernizer
146 | verify
147 |
148 | modernizer
149 |
150 |
151 |
152 |
153 | 1.7
154 |
155 |
156 |
157 |
158 |
159 |
160 | UTF-8
161 | 1.9.0
162 |
163 |
164 |
165 | 3.0.5
166 |
167 |
168 |
169 |
170 | args4j
171 | args4j
172 | 2.0.31
173 |
174 |
175 | ch.qos.logback
176 | logback-classic
177 | 1.2.13
178 |
179 |
180 | junit
181 | junit
182 | 4.13.1
183 | test
184 |
185 |
186 | org.apache.jclouds
187 | jclouds-allblobstore
188 | ${jclouds.version}
189 |
190 |
191 | org.apache.jclouds.driver
192 | jclouds-slf4j
193 | ${jclouds.version}
194 |
195 |
196 | org.apache.jclouds.labs
197 | google-cloud-storage
198 | ${jclouds.version}
199 |
200 |
201 | org.apache.jclouds.labs
202 | rackspace-cloudfiles-uk
203 | ${jclouds.version}
204 |
205 |
206 | org.apache.jclouds.labs
207 | rackspace-cloudfiles-us
208 | ${jclouds.version}
209 |
210 |
211 | org.assertj
212 | assertj-core
213 | test
214 | 2.0.0
215 |
216 |
217 | org.slf4j
218 | slf4j-api
219 | 1.7.10
220 |
221 |
222 |
223 |
--------------------------------------------------------------------------------
/src/main/assembly/jar-with-dependencies.xml:
--------------------------------------------------------------------------------
1 |
4 | jar-with-dependencies
5 |
6 | jar
7 |
8 | false
9 |
10 |
11 | metaInf-services
12 |
13 |
14 |
15 |
16 | /
17 | true
18 | true
19 | runtime
20 |
21 |
22 |
23 |
24 | ${project.basedir}/src/main/config
25 | /
26 |
27 | logback.xml
28 |
29 | true
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/main/java/org/gaul/areweconsistentyet/AreWeConsistentYet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Andrew Gaul
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.gaul.areweconsistentyet;
18 |
19 | import static java.util.Objects.requireNonNull;
20 |
21 | import static com.google.common.base.Preconditions.checkArgument;
22 |
23 | import java.io.File;
24 | import java.io.FileInputStream;
25 | import java.io.IOException;
26 | import java.io.InputStream;
27 | import java.io.PrintStream;
28 | import java.util.Arrays;
29 | import java.util.HashSet;
30 | import java.util.Properties;
31 | import java.util.Random;
32 | import java.util.Set;
33 |
34 | import com.google.common.collect.ImmutableList;
35 | import com.google.common.io.ByteSource;
36 | import com.google.common.io.ByteStreams;
37 | import com.google.inject.Module;
38 |
39 | import org.jclouds.Constants;
40 | import org.jclouds.ContextBuilder;
41 | import org.jclouds.blobstore.BlobStore;
42 | import org.jclouds.blobstore.BlobStoreContext;
43 | import org.jclouds.blobstore.domain.Blob;
44 | import org.jclouds.blobstore.domain.PageSet;
45 | import org.jclouds.blobstore.domain.StorageMetadata;
46 | import org.jclouds.blobstore.options.ListContainerOptions;
47 | import org.jclouds.domain.Location;
48 | import org.jclouds.io.Payload;
49 | import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
50 | import org.kohsuke.args4j.CmdLineException;
51 | import org.kohsuke.args4j.CmdLineParser;
52 | import org.kohsuke.args4j.Option;
53 |
54 | public final class AreWeConsistentYet {
55 | private final ByteSource payload1;
56 | private final ByteSource payload2;
57 | private final BlobStore blobStore;
58 | private final BlobStore blobStoreRead;
59 | private final String containerName;
60 | private final int iterations;
61 | private final Random random = new Random();
62 |
63 | public AreWeConsistentYet(BlobStore blobStore,
64 | BlobStore blobStoreRead, String containerName, int iterations,
65 | long objectSize) {
66 | this.blobStore = requireNonNull(blobStore);
67 | this.blobStoreRead = requireNonNull(blobStoreRead);
68 | this.containerName = requireNonNull(containerName);
69 | checkArgument(iterations > 0,
70 | "iterations must be greater than zero, was: " + iterations);
71 | this.iterations = iterations;
72 | checkArgument(objectSize > 0,
73 | "object size must be greater than zero, was: " + objectSize);
74 | payload1 = Utils.infiniteByteSource((byte) 1).slice(0, objectSize);
75 | payload2 = Utils.infiniteByteSource((byte) 2).slice(0, objectSize);
76 | }
77 |
78 | public int readAfterCreate() throws IOException {
79 | int count = 0;
80 | for (int i = 0; i < iterations; ++i) {
81 | String blobName = makeBlobName();
82 | blobStore.putBlob(containerName, makeBlob(blobName, payload1));
83 | Blob getBlob = blobStoreRead.getBlob(containerName, blobName);
84 | if (getBlob == null) {
85 | ++count;
86 | } else {
87 | try (Payload payload = getBlob.getPayload();
88 | InputStream is = payload.openStream()) {
89 | ByteStreams.copy(is, ByteStreams.nullOutputStream());
90 | }
91 | }
92 | blobStore.removeBlob(containerName, blobName);
93 | }
94 | return count;
95 | }
96 |
97 | public int readAfterDelete() throws IOException {
98 | int count = 0;
99 | for (int i = 0; i < iterations; ++i) {
100 | String blobName = makeBlobName();
101 | blobStoreRead.putBlob(containerName, makeBlob(blobName, payload1));
102 | blobStore.removeBlob(containerName, blobName);
103 | Blob getBlob = blobStoreRead.getBlob(containerName, blobName);
104 | if (getBlob != null) {
105 | ++count;
106 | try (Payload payload = getBlob.getPayload();
107 | InputStream is = payload.openStream()) {
108 | ByteStreams.copy(is, ByteStreams.nullOutputStream());
109 | }
110 | }
111 | }
112 | return count;
113 | }
114 |
115 | public int readAfterOverwrite() throws IOException {
116 | int count = 0;
117 | for (int i = 0; i < iterations; ++i) {
118 | String blobName = makeBlobName();
119 | blobStore.putBlob(containerName, makeBlob(blobName, payload1));
120 | blobStore.putBlob(containerName, makeBlob(blobName, payload2));
121 | Blob getBlob = blobStoreRead.getBlob(containerName, blobName);
122 | if (getBlob == null) {
123 | ++count;
124 | continue;
125 | }
126 | try (Payload payload = getBlob.getPayload();
127 | InputStream is = payload.openStream()) {
128 | if (Arrays.equals(payload1.read(), ByteStreams.toByteArray(
129 | is))) {
130 | ++count;
131 | }
132 | }
133 | blobStore.removeBlob(containerName, blobName);
134 | }
135 | return count;
136 | }
137 |
138 | public int listAfterCreate() throws IOException {
139 | int count = 0;
140 | for (int i = 0; i < iterations; ++i) {
141 | String blobName = makeBlobName();
142 | blobStore.putBlob(containerName, makeBlob(blobName, payload1));
143 | if (!listAllBlobs().contains(blobName)) {
144 | ++count;
145 | }
146 | blobStore.removeBlob(containerName, blobName);
147 | }
148 | return count;
149 | }
150 |
151 | public int listAfterDelete() throws IOException {
152 | int count = 0;
153 | for (int i = 0; i < iterations; ++i) {
154 | String blobName = makeBlobName();
155 | blobStoreRead.putBlob(containerName, makeBlob(blobName, payload1));
156 | blobStore.removeBlob(containerName, blobName);
157 | if (listAllBlobs().contains(blobName)) {
158 | ++count;
159 | }
160 | }
161 | return count;
162 | }
163 |
164 | private String makeBlobName() {
165 | return "blob-name-" + random.nextInt(Integer.MAX_VALUE);
166 | }
167 |
168 | private Blob makeBlob(String blobName, ByteSource payload)
169 | throws IOException {
170 | return blobStore.blobBuilder(blobName)
171 | .payload(payload)
172 | .contentLength(payload.size())
173 | .build();
174 | }
175 |
176 | private Set listAllBlobs() {
177 | Set blobNames = new HashSet();
178 | ListContainerOptions options = new ListContainerOptions();
179 | while (true) {
180 | PageSet extends StorageMetadata> set = blobStoreRead.list(
181 | containerName, options);
182 | for (StorageMetadata sm : set) {
183 | blobNames.add(sm.getName());
184 | }
185 | String marker = set.getNextMarker();
186 | if (marker == null) {
187 | break;
188 | }
189 | options = options.afterMarker(marker);
190 | }
191 | return blobNames;
192 | }
193 |
194 | static final class Options {
195 | @Option(name = "--container-name",
196 | usage = "container name for tests, will be created and removed",
197 | required = true)
198 | private String containerName;
199 |
200 | @Option(name = "--iterations",
201 | usage = "number of iterations (default: 1)")
202 | private int iterations = 1;
203 |
204 | @Option(name = "--location", usage = "container location")
205 | private String location;
206 |
207 | @Option(name = "--size", usage = "object size in bytes (default: 1)")
208 | private long objectSize = 1;
209 |
210 | @Option(name = "--properties", usage = "configuration file",
211 | required = true)
212 | private File propertiesFile;
213 |
214 | @Option(name = "--reader-endpoint",
215 | usage = "separate endpoint to read from")
216 | private String readerEndpoint;
217 | }
218 |
219 | public static void main(String[] args) throws Exception {
220 | Options options = new Options();
221 | CmdLineParser parser = new CmdLineParser(options);
222 | try {
223 | parser.parseArgument(args);
224 | } catch (CmdLineException cle) {
225 | PrintStream err = System.err;
226 | err.println("are-we-consistent-yet version " +
227 | AreWeConsistentYet.class.getPackage()
228 | .getImplementationVersion());
229 | err.println("Usage: are-we-consistent-yet" +
230 | " --container-name NAME --properties FILE [options...]");
231 | parser.printUsage(err);
232 | System.exit(1);
233 | }
234 |
235 | Properties properties = new Properties();
236 | try (InputStream is = new FileInputStream(options.propertiesFile)) {
237 | properties.load(is);
238 | }
239 | Properties propertiesRead = (Properties) properties.clone();
240 | if (options.readerEndpoint != null) {
241 | propertiesRead.setProperty(Constants.PROPERTY_ENDPOINT,
242 | options.readerEndpoint);
243 | }
244 |
245 | try (BlobStoreContext context = blobStoreContextFromProperties(
246 | properties);
247 | BlobStoreContext contextRead = blobStoreContextFromProperties(
248 | propertiesRead)) {
249 | BlobStore blobStore = context.getBlobStore();
250 | BlobStore blobStoreRead = contextRead.getBlobStore();
251 |
252 | Location location = null;
253 | if (options.location != null) {
254 | for (Location loc : blobStore.listAssignableLocations()) {
255 | if (loc.getId().equalsIgnoreCase(options.location)) {
256 | location = loc;
257 | break;
258 | }
259 | }
260 | if (location == null) {
261 | throw new Exception("Could not find location: " +
262 | options.location);
263 | }
264 | }
265 | blobStore.createContainerInLocation(location,
266 | options.containerName);
267 | AreWeConsistentYet test = new AreWeConsistentYet(
268 | blobStore, blobStoreRead, options.containerName,
269 | options.iterations, options.objectSize);
270 | PrintStream out = System.out;
271 | out.println("eventual consistency count with " +
272 | options.iterations + " iterations: ");
273 | out.println("read after create: " + test.readAfterCreate());
274 | out.println("read after delete: " + test.readAfterDelete());
275 | out.println("read after overwrite: " + test.readAfterOverwrite());
276 | out.println("list after create: " + test.listAfterCreate());
277 | out.println("list after delete: " + test.listAfterDelete());
278 | blobStore.deleteContainer(options.containerName);
279 | }
280 | }
281 |
282 | private static BlobStoreContext blobStoreContextFromProperties(
283 | Properties properties) {
284 | String provider = properties.getProperty(Constants.PROPERTY_PROVIDER);
285 | String identity = properties.getProperty(Constants.PROPERTY_IDENTITY);
286 | String credential = properties.getProperty(
287 | Constants.PROPERTY_CREDENTIAL);
288 | String endpoint = properties.getProperty(Constants.PROPERTY_ENDPOINT);
289 | if (provider == null || identity == null || credential == null) {
290 | System.err.println("Properties file must contain:\n" +
291 | Constants.PROPERTY_PROVIDER + "\n" +
292 | Constants.PROPERTY_IDENTITY + "\n" +
293 | Constants.PROPERTY_CREDENTIAL);
294 | System.exit(1);
295 | }
296 |
297 | ContextBuilder builder = ContextBuilder
298 | .newBuilder(provider)
299 | .credentials(identity, credential)
300 | .modules(ImmutableList.of(new SLF4JLoggingModule()))
301 | .overrides(properties);
302 | if (endpoint != null) {
303 | builder = builder.endpoint(endpoint);
304 | }
305 | return builder.build(BlobStoreContext.class);
306 | }
307 | }
308 |
--------------------------------------------------------------------------------
/src/main/java/org/gaul/areweconsistentyet/Utils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Andrew Gaul
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.gaul.areweconsistentyet;
18 |
19 | import java.io.IOException;
20 | import java.io.InputStream;
21 | import java.util.Arrays;
22 |
23 | import com.google.common.io.ByteSource;
24 |
25 | final class Utils {
26 | private Utils() {
27 | throw new AssertionError("intentionally unimplemented");
28 | }
29 |
30 | static ByteSource infiniteByteSource(byte fill) {
31 | return new InfiniteByteSource(fill);
32 | }
33 |
34 | private static class InfiniteByteSource extends ByteSource {
35 | private final byte fill;
36 |
37 | InfiniteByteSource(byte fill) {
38 | this.fill = fill;
39 | }
40 |
41 | @Override
42 | public InputStream openStream() {
43 | return new InfiniteByteStream(fill);
44 | }
45 | }
46 |
47 | private static class InfiniteByteStream extends InputStream {
48 | private final byte fill;
49 |
50 | InfiniteByteStream(byte fill) {
51 | this.fill = fill;
52 | }
53 |
54 | @Override
55 | public synchronized int read() {
56 | return fill;
57 | }
58 |
59 | @Override
60 | public synchronized int read(byte[] b) throws IOException {
61 | return read(b, 0, b.length);
62 | }
63 |
64 | @Override
65 | public synchronized int read(byte[] b, int off, int len)
66 | throws IOException {
67 | Arrays.fill(b, off, len, fill);
68 | return len;
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/resources/checkstyle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
--------------------------------------------------------------------------------
/src/main/resources/copyright_header.txt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Andrew Gaul
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
--------------------------------------------------------------------------------
/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | %.-1p %d{MM-dd HH:mm:ss.SSS} %t %c{30}:%L %X{clientId}|%X{sessionId}:%X{messageId}:%X{fileId}] %m%n
5 |
6 |
7 | ${LOG_LEVEL:-info}
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/test/java/org/gaul/areweconsistentyet/AreWeConsistentYetTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Andrew Gaul
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.gaul.areweconsistentyet;
18 |
19 | import static org.assertj.core.api.Assertions.assertThat;
20 |
21 | import com.google.common.collect.ImmutableList;
22 | import com.google.common.io.Closer;
23 | import com.google.inject.Module;
24 |
25 | import org.jclouds.ContextBuilder;
26 | import org.jclouds.blobstore.BlobStore;
27 | import org.jclouds.blobstore.BlobStoreContext;
28 | import org.jclouds.domain.Location;
29 | import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
30 | import org.junit.After;
31 | import org.junit.Before;
32 | import org.junit.Test;
33 |
34 | public final class AreWeConsistentYetTest {
35 | private static final int ITERATIONS = 1;
36 | private static final int OBJECT_SIZE = 1;
37 | // model eventual consistency with two stores that never reconcile
38 | private BlobStoreContext context;
39 | private BlobStoreContext contextRead;
40 | private AreWeConsistentYet awcyStrong;
41 | private AreWeConsistentYet awcyEventual;
42 |
43 | @Before
44 | public void setUp() throws Exception {
45 | ContextBuilder builder = ContextBuilder
46 | .newBuilder("transient")
47 | .credentials("identity", "credential")
48 | .modules(ImmutableList.of(new SLF4JLoggingModule()));
49 | context = builder.build(BlobStoreContext.class);
50 | contextRead = builder.build(BlobStoreContext.class);
51 |
52 | BlobStore blobStore = context.getBlobStore();
53 | BlobStore blobStoreRead = contextRead.getBlobStore();
54 |
55 | String containerName = "container-name";
56 | Location location = null;
57 | blobStore.createContainerInLocation(location, containerName);
58 | blobStoreRead.createContainerInLocation(location, containerName);
59 |
60 | awcyStrong = new AreWeConsistentYet(blobStore,
61 | blobStore, containerName, ITERATIONS, OBJECT_SIZE);
62 | awcyEventual = new AreWeConsistentYet(blobStore,
63 | blobStoreRead, containerName, ITERATIONS, OBJECT_SIZE);
64 | }
65 |
66 | @After
67 | public void tearDown() throws Exception {
68 | try (Closer closer = Closer.create()) {
69 | closer.register(context);
70 | closer.register(contextRead);
71 | }
72 | }
73 |
74 | @Test
75 | public void testReadAfterCreate() throws Exception {
76 | assertThat(awcyStrong.readAfterCreate()).isEqualTo(0);
77 | assertThat(awcyEventual.readAfterCreate()).isEqualTo(ITERATIONS);
78 | }
79 |
80 | @Test
81 | public void testReadAfterDelete() throws Exception {
82 | assertThat(awcyStrong.readAfterDelete()).isEqualTo(0);
83 | assertThat(awcyEventual.readAfterDelete()).isEqualTo(ITERATIONS);
84 | }
85 |
86 | @Test
87 | public void testReadAfterOverwrite() throws Exception {
88 | assertThat(awcyStrong.readAfterOverwrite()).isEqualTo(0);
89 | assertThat(awcyEventual.readAfterOverwrite()).isEqualTo(ITERATIONS);
90 | }
91 |
92 | @Test
93 | public void testListAfterCreate() throws Exception {
94 | assertThat(awcyStrong.listAfterCreate()).isEqualTo(0);
95 | assertThat(awcyEventual.listAfterCreate()).isEqualTo(ITERATIONS);
96 | }
97 |
98 | @Test
99 | public void testListAfterDelete() throws Exception {
100 | assertThat(awcyStrong.listAfterDelete()).isEqualTo(0);
101 | assertThat(awcyEventual.listAfterDelete()).isEqualTo(ITERATIONS);
102 | }
103 | }
104 |
--------------------------------------------------------------------------------