Skip to content

Commit

Permalink
Cleanup documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsimsa committed Mar 8, 2017
1 parent 70208ee commit c223305
Show file tree
Hide file tree
Showing 28 changed files with 286 additions and 264 deletions.
19 changes: 18 additions & 1 deletion core/common/src/main/java/alluxio/util/URIUtils.java
Expand Up @@ -11,9 +11,13 @@


package alluxio.util; package alluxio.util;


import alluxio.util.io.PathUtils;

import com.google.common.base.Joiner; import com.google.common.base.Joiner;


import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
Expand All @@ -23,7 +27,7 @@
import javax.annotation.concurrent.ThreadSafe; import javax.annotation.concurrent.ThreadSafe;


/** /**
* Utility methods for working with {@link alluxio.AlluxioURI}. * Utility methods for working with URIs.
*/ */
@ThreadSafe @ThreadSafe
public final class URIUtils { public final class URIUtils {
Expand All @@ -32,6 +36,19 @@ public final class URIUtils {


private URIUtils() {} // prevent instantiation private URIUtils() {} // prevent instantiation


/**
* Appends the given path to the given base URI.
*
* @param base the base URI
* @param path the path to append
* @return the URI resulting from appending the base and the path
* @throws URISyntaxException if URI syntax error is encountered
*/
public static URI appendPath(URI base, String path) throws URISyntaxException {
return new URI(base.getScheme(), base.getHost(), PathUtils.concatPath(base.getPath(), path),
null);
}

/** /**
* Generates a query string from a {@link Map <String, String>} of key/value pairs. * Generates a query string from a {@link Map <String, String>} of key/value pairs.
* *
Expand Down
Expand Up @@ -11,8 +11,13 @@


package alluxio.master.journal; package alluxio.master.journal;


import java.net.URL; import java.net.URI;


/**
* Interface for managing the checkpoint for a journal. The {@link #update(URI)} method will
* update the journal's checkpoint to the specified location, and
* {@link #recover()} will recover from any failures that may occur during {@link #update(URI)}.
*/
public interface CheckpointManager { public interface CheckpointManager {


/** /**
Expand All @@ -21,9 +26,9 @@ public interface CheckpointManager {
void recover(); void recover();


/** /**
* Updates the checkpoint to the specified URL. * Updates the checkpoint to the specified URI.
* *
* @param newCheckpoint the URL to the new checkpoint * @param location the location of the new checkpoint
*/ */
void update(URL newCheckpoint); void update(URI location);
} }
Expand Up @@ -11,24 +11,18 @@


package alluxio.master.journal; package alluxio.master.journal;


import java.net.URL; import java.net.URI;


import javax.annotation.concurrent.ThreadSafe; import javax.annotation.concurrent.ThreadSafe;


/** /**
* This class encapsulates the journal for a master. The journal is made up of 2 components: * This class represents a journal.
* - The checkpoint: the full state of the master
* - The entries: incremental entries to apply to the checkpoint.
*
* To construct the full state of the master, all the entries must be applied to the checkpoint in
* order. The entry file most recently being written to is in the base journal folder, where the
* completed entry files are in the "completed/" sub-directory.
*/ */
@ThreadSafe @ThreadSafe
public interface Journal { public interface Journal {


/** /**
* @return the location for this journal * @return the journal location
*/ */
URL getLocation(); URI getLocation();
} }
Expand Up @@ -13,13 +13,13 @@


import alluxio.master.journal.ufs.ReadOnlyUfsJournal; import alluxio.master.journal.ufs.ReadOnlyUfsJournal;
import alluxio.master.journal.ufs.ReadWriteUfsJournal; import alluxio.master.journal.ufs.ReadWriteUfsJournal;
import alluxio.master.journal.ufs.UfsJournal; import alluxio.util.URIUtils;


import java.net.MalformedURLException; import java.net.URI;
import java.net.URL; import java.net.URISyntaxException;


/** /**
* Interface for factories which create {@link UfsJournal}s. * Interface for factories which create {@link Journal}s.
*/ */
public interface JournalFactory { public interface JournalFactory {
/** /**
Expand All @@ -32,7 +32,7 @@ public interface JournalFactory {
* A factory which creates read-write journals. * A factory which creates read-write journals.
*/ */
final class ReadWrite implements JournalFactory { final class ReadWrite implements JournalFactory {
private final URL mBaseLocation; private final URI mBaseLocation;


/** /**
* Creates a journal factory with the specified base location. When journals are * Creates a journal factory with the specified base location. When journals are
Expand All @@ -42,16 +42,16 @@ final class ReadWrite implements JournalFactory {
* *
* @param baseLocation the base location for journals created by this factory * @param baseLocation the base location for journals created by this factory
*/ */
public ReadWrite(URL baseLocation) { public ReadWrite(URI baseLocation) {
mBaseLocation = baseLocation; mBaseLocation = baseLocation;
} }


@Override @Override
public UfsJournal get(String name) { public Journal get(String name) {
try { try {
return new ReadWriteUfsJournal(new URL(mBaseLocation, name)); return new ReadWriteUfsJournal(URIUtils.appendPath(mBaseLocation, name));
} catch (MalformedURLException e) { } catch (URISyntaxException e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(e);
} }
} }
} }
Expand All @@ -60,26 +60,26 @@ public UfsJournal get(String name) {
* A factory which creates read-only journals. * A factory which creates read-only journals.
*/ */
final class ReadOnly implements JournalFactory { final class ReadOnly implements JournalFactory {
private final URL mBaseLocation; private final URI mBaseLocation;


/** /**
* Creates a journal factory with the specified base location. When journals are * Creates a journal factory with the specified base location. When journals are
* created, their names are appended to the base path. * created, their names are appended to the base path.
* *
* Journals created by this factory only support reads. * Journals created by this factory only support reading.
* *
* @param baseLocation the base location for journals created by this factory * @param baseLocation the base location for journals created by this factory
*/ */
public ReadOnly(URL baseLocation) { public ReadOnly(URI baseLocation) {
mBaseLocation = baseLocation; mBaseLocation = baseLocation;
} }


@Override @Override
public UfsJournal get(String name) { public Journal get(String name) {
try { try {
return new ReadOnlyUfsJournal(new URL(mBaseLocation, name)); return new ReadOnlyUfsJournal(URIUtils.appendPath(mBaseLocation, name));
} catch (MalformedURLException e) { } catch (URISyntaxException e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(e);
} }
} }
} }
Expand Down
Expand Up @@ -16,8 +16,7 @@
import java.io.IOException; import java.io.IOException;


/** /**
* This input stream retrieves {@link JournalEntry} from journal checkpoint files and journal log * This input stream retrieves {@link JournalEntry} from journal checkpoints and journal logs.
* files.
*/ */
public interface JournalInputStream { public interface JournalInputStream {
/** /**
Expand Down
Expand Up @@ -17,7 +17,7 @@


/** /**
* This output stream writes {@link JournalEntry} objects to the journal. This output stream can * This output stream writes {@link JournalEntry} objects to the journal. This output stream can
* write to both the journal checkpoint file, or the journal log files. * write to both the journal checkpoint and the journal logs.
*/ */
public interface JournalOutputStream { public interface JournalOutputStream {
/** /**
Expand Down
Expand Up @@ -20,8 +20,8 @@
* *
* 1. First, the checkpoint must be read. * 1. First, the checkpoint must be read.
* *
* 2. Afterwards, completed entries are read in order. Only completed logs are read, so the last log * 2. Afterwards, logs are read in order they were created. Only completed logs are read, so the
* currently being written is not read until it is marked as complete. * last log currently being written is not read until it is marked as complete.
*/ */
@NotThreadSafe @NotThreadSafe
public interface JournalReader { public interface JournalReader {
Expand All @@ -38,21 +38,21 @@ public interface JournalReader {
* Gets the {@link JournalInputStream} for the journal checkpoint. This must be called before * Gets the {@link JournalInputStream} for the journal checkpoint. This must be called before
* calling {@link #getNextInputStream()}. * calling {@link #getNextInputStream()}.
* *
* @return the {@link JournalInputStream} for the journal checkpoint file * @return the {@link JournalInputStream} for the journal checkpoint
* @throws IOException if the checkpoint file cannot be read, or was already read * @throws IOException if the checkpoint cannot be read, or was already read
*/ */
JournalInputStream getCheckpointInputStream() throws IOException; JournalInputStream getCheckpointInputStream() throws IOException;


/** /**
* @return the input stream for the next completed log file. Will return null if the next * @return the input stream for the next completed log. Will return null if the next
* completed log file does not exist yet. * completed log does not exist yet.
* @throws IOException if the reader is no longer valid or when trying to get an input stream * @throws IOException if the reader is no longer valid or when trying to get an input stream
* before a checkpoint was read * before a checkpoint was read
*/ */
JournalInputStream getNextInputStream() throws IOException; JournalInputStream getNextInputStream() throws IOException;


/** /**
* @return the last modified time of the checkpoint file in ms * @return the last modified time of the checkpoint in ms
* @throws IOException if the checkpoint does not exist * @throws IOException if the checkpoint does not exist
*/ */
long getCheckpointLastModifiedTimeMs() throws IOException; long getCheckpointLastModifiedTimeMs() throws IOException;
Expand Down
Expand Up @@ -33,8 +33,6 @@ public final class JournalTailer {


/** The master to apply all the journal entries to. */ /** The master to apply all the journal entries to. */
private final Master mMaster; private final Master mMaster;
/** The journal to tail. */
private final Journal mJournal;
/** The journal reader to read journal entries. */ /** The journal reader to read journal entries. */
private final JournalReader mReader; private final JournalReader mReader;
/** This keeps track of the latest sequence number seen in the journal entries. */ /** This keeps track of the latest sequence number seen in the journal entries. */
Expand All @@ -48,8 +46,7 @@ public final class JournalTailer {
*/ */
public JournalTailer(Master master, Journal journal) { public JournalTailer(Master master, Journal journal) {
mMaster = Preconditions.checkNotNull(master); mMaster = Preconditions.checkNotNull(master);
mJournal = Preconditions.checkNotNull(journal); mReader = ((ReadOnlyUfsJournal) journal).getNewReader();
mReader = ((ReadOnlyUfsJournal) mJournal).getNewReader();
} }


/** /**
Expand Down
Expand Up @@ -18,14 +18,13 @@
/** /**
* This class manages all the writes to the journal. Journal writes happen in two phases: * This class manages all the writes to the journal. Journal writes happen in two phases:
* *
* 1. First the checkpoint file is written. The checkpoint file contains entries reflecting the * 1. First the checkpoint is written. The checkpoint contains entries reflecting the
* state of the master with all of the completed logs applied. * state of the master with all of the completed logs applied.
* *
* 2. Afterwards, entries are appended to log files. The checkpoint file must be written before the * 2. Afterwards, entries are appended to log. The checkpoint must be written before the logs.
* log files.
* *
* The latest state can be reconstructed by reading the checkpoint file, and applying all the * The latest state can be reconstructed by reading the checkpoint, and applying all the
* completed logs and then the remaining log in progress. * completed logs and finally the current log.
*/ */
public interface JournalWriter { public interface JournalWriter {


Expand Down Expand Up @@ -77,7 +76,7 @@ public interface JournalWriter {
void close() throws IOException; void close() throws IOException;


/** /**
* Recovers the checkpoint file in case the master crashed while updating it previously. * Recovers the checkpoint in case the master crashed while updating it previously.
*/ */
void recover(); void recover();


Expand All @@ -89,8 +88,8 @@ public interface JournalWriter {
void deleteCompletedLogs() throws IOException; void deleteCompletedLogs() throws IOException;


/** /**
* Moves the current log file to the completed folder, marking it as complete. If successful, the * Marks the current log as completed. If successful, the current log will no longer exist. The
* current log file will no longer exist. The current log must already be closed before this call. * current log must be closed before this call.
* *
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
Expand Down
Expand Up @@ -14,19 +14,19 @@
import alluxio.master.journal.JournalReader; import alluxio.master.journal.JournalReader;
import alluxio.master.journal.ReadOnlyJournal; import alluxio.master.journal.ReadOnlyJournal;


import java.net.URL; import java.net.URI;


import javax.annotation.concurrent.ThreadSafe; import javax.annotation.concurrent.ThreadSafe;


/** /**
* The read-only journal. It prevents access to a {@link UfsJournalWriter}. * Implementation of {@link ReadOnlyJournal} based on UFS.
*/ */
@ThreadSafe @ThreadSafe
public class ReadOnlyUfsJournal extends UfsJournal implements ReadOnlyJournal { public class ReadOnlyUfsJournal extends UfsJournal implements ReadOnlyJournal {
/** /**
* @param location the location for the journal * @param location the location for the journal
*/ */
public ReadOnlyUfsJournal(URL location) { public ReadOnlyUfsJournal(URI location) {
super(location); super(location);
} }


Expand Down
Expand Up @@ -14,19 +14,19 @@
import alluxio.master.journal.JournalWriter; import alluxio.master.journal.JournalWriter;
import alluxio.master.journal.ReadWriteJournal; import alluxio.master.journal.ReadWriteJournal;


import java.net.URL; import java.net.URI;


import javax.annotation.concurrent.ThreadSafe; import javax.annotation.concurrent.ThreadSafe;


/** /**
* The read-write journal. This allows both reads and writes to the journal. * Implementation of {@link ReadWriteJournal} based on UFS.
*/ */
@ThreadSafe @ThreadSafe
public class ReadWriteUfsJournal extends ReadOnlyUfsJournal implements ReadWriteJournal { public class ReadWriteUfsJournal extends ReadOnlyUfsJournal implements ReadWriteJournal {
/** /**
* @param location the location for the journal * @param location the location for the journal
*/ */
public ReadWriteUfsJournal(URL location) { public ReadWriteUfsJournal(URI location) {
super(location); super(location);
} }


Expand Down

0 comments on commit c223305

Please sign in to comment.