You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by al...@apache.org on 2014/03/04 15:54:26 UTC
svn commit: r1574120 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment:
SegmentNodeStoreService.java http/HttpStore.java
Author: alexparvulescu
Date: Tue Mar 4 14:54:26 2014
New Revision: 1574120
URL: http://svn.apache.org/r1574120
Log:
OAK-1161 Simple failover for TarMK-based installations
Small changes:
- added the ability to unwrap the SegmentStore from the service
- refactored the URL parts so the HttpStore can be extended easily
- Journal#setHead now returns true instead of throwing an exception, left in a TODO to not forget about this issue
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/http/HttpStore.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java?rev=1574120&r1=1574119&r2=1574120&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java Tue Mar 4 14:54:26 2014
@@ -71,6 +71,10 @@ public class SegmentNodeStoreService ext
return delegate;
}
+ public SegmentStore getSegmentStore() {
+ return store;
+ }
+
@Activate
public synchronized void activate(ComponentContext context)
throws IOException {
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/http/HttpStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/http/HttpStore.java?rev=1574120&r1=1574119&r2=1574120&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/http/HttpStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/http/HttpStore.java Tue Mar 4 14:54:26 2014
@@ -45,52 +45,65 @@ public class HttpStore extends AbstractS
private final URL base;
- protected HttpStore(URL base, int cacheSizeMB) {
+ /**
+ * @param base
+ * make sure the url ends with a slash "/", otherwise the
+ * requests will end up as absolute instead of relative
+ * @param cacheSizeMB
+ */
+ public HttpStore(URL base, int cacheSizeMB) {
super(cacheSizeMB);
this.base = base;
}
+ protected URLConnection get(String fragment) throws MalformedURLException,
+ IOException {
+ return new URL(base, fragment).openConnection();
+ }
+
@Override
- public Journal getJournal(String name) {
- try {
- final URL url = new URL(base, "/j/" + name);
- return new Journal() {
- @Override
- public RecordId getHead() {
+ public Journal getJournal(final String name) {
+ return new Journal() {
+ @Override
+ public RecordId getHead() {
+ try {
+ final URLConnection connection = get("j/" + name);
+ InputStream stream = connection.getInputStream();
try {
- InputStream stream = url.openStream();
- try {
- BufferedReader reader = new BufferedReader(
- new InputStreamReader(stream, UTF_8));
- return RecordId.fromString(reader.readLine());
- } finally {
- stream.close();
- }
- } catch (IllegalArgumentException e) {
- throw new IllegalStateException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
+ BufferedReader reader = new BufferedReader(
+ new InputStreamReader(stream, UTF_8));
+ return RecordId.fromString(reader.readLine());
+ } finally {
+ stream.close();
}
+ } catch (IllegalArgumentException e) {
+ throw new IllegalStateException(e);
+ } catch (MalformedURLException e) {
+ throw new IllegalStateException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
}
- @Override
- public boolean setHead(RecordId base, RecordId head) {
- throw new UnsupportedOperationException();
- }
- @Override
- public void merge() {
- throw new UnsupportedOperationException();
- }
- };
- } catch (MalformedURLException e) {
- throw new IllegalStateException(e);
- }
+ }
+
+ @Override
+ public boolean setHead(RecordId base, RecordId head) {
+ // TODO throw new UnsupportedOperationException();
+ return true;
+ }
+
+ @Override
+ public void merge() {
+ throw new UnsupportedOperationException();
+ }
+ };
}
- @Override @CheckForNull
+ @Override
+ @CheckForNull
protected Segment loadSegment(UUID id) {
try {
- URL url = new URL(base, "/s/" + id);
- InputStream stream = url.openStream();
+ final URLConnection connection = get("s/" + id);
+ InputStream stream = connection.getInputStream();
try {
byte[] data = ByteStreams.toByteArray(stream);
return new Segment(this, factory, id, ByteBuffer.wrap(data));
@@ -105,11 +118,10 @@ public class HttpStore extends AbstractS
}
@Override
- public void writeSegment(
- UUID segmentId, byte[] bytes, int offset, int length) {
+ public void writeSegment(UUID segmentId, byte[] bytes, int offset,
+ int length) {
try {
- URL url = new URL(base, "/s/" + segmentId);
- URLConnection connection = url.openConnection();
+ URLConnection connection = get("s/" + segmentId);
connection.setDoInput(false);
connection.setDoOutput(true);
OutputStream stream = connection.getOutputStream();