From: <tho...@us...> - 2014-03-13 16:57:22
|
Revision: 7957 http://sourceforge.net/p/bigdata/code/7957 Author: thompsonbry Date: 2014-03-13 16:57:19 +0000 (Thu, 13 Mar 2014) Log Message: ----------- Examination of #853. Unable to replicate the problem. Ticket is closed. I did identify some problems with the ability to specify GET versus POST for a SPARQL QUERY. That issue has been fixed. I wrote unit tests which verify that POST and GET for a SPARQL QUERY are both allowed on the follower. Modified Paths: -------------- branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/test/com/bigdata/journal/jini/ha/TestHA3JournalServer.java branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepository.java branches/RDR/bigdata-jini/src/test/com/bigdata/journal/jini/ha/TestHA3JournalServer.java branches/RDR/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepository.java Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/test/com/bigdata/journal/jini/ha/TestHA3JournalServer.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/test/com/bigdata/journal/jini/ha/TestHA3JournalServer.java 2014-03-13 16:21:32 UTC (rev 7956) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/test/com/bigdata/journal/jini/ha/TestHA3JournalServer.java 2014-03-13 16:57:19 UTC (rev 7957) @@ -49,6 +49,7 @@ import com.bigdata.ha.halog.IHALogReader; import com.bigdata.ha.msg.HARootBlockRequest; import com.bigdata.journal.AbstractJournal; +import com.bigdata.journal.jini.ha.AbstractHA3JournalServerTestCase.ABC; import com.bigdata.journal.jini.ha.HAJournalTest.HAGlueTest; import com.bigdata.quorum.Quorum; import com.bigdata.rdf.sail.webapp.client.RemoteRepository; @@ -3477,4 +3478,65 @@ } } + /** + * Test verifies that we can POST a SPARQL query to a follower. + * + * @see <a href="http://trac.bigdata.com/ticket/853"> Follower does not + * accept POST of idempotent operations (HA) </a> + */ + public void test_postQueryOnFollowers() throws Exception { + + final ABC abc = new ABC(false/*sequential*/); // simultaneous start. + + final HAGlue serverA = abc.serverA, serverB = abc.serverB, serverC = abc.serverC; + + // Verify quorum is FULLY met. + awaitFullyMetQuorum(); + + // await the KB create commit point to become visible on each service. + awaitCommitCounter(1L, new HAGlue[] { serverA, serverB, serverC }); + + // Verify binary equality of ALL journals. + assertDigestsEquals(new HAGlue[] { serverA, serverB, serverC }); + + final RemoteRepository[] repos = new RemoteRepository[3]; + repos[0] = getRemoteRepository(serverA); + repos[1] = getRemoteRepository(serverB); + repos[2] = getRemoteRepository(serverC); + + /* + * Verify that query on all nodes is allowed. + */ + for (RemoteRepository r : repos) { + + r.setQueryMethod("GET"); + + // Should be empty. + assertEquals(0L, + countResults(r.prepareTupleQuery("SELECT * {?a ?b ?c}") + .evaluate())); + + } + + // Change the maximum length of a GET for a Query. + for(RemoteRepository r : repos) { + + r.setMaxRequestURLLength(1); + + } + + // Run with the new length. All requests should be POSTs. + for (RemoteRepository r : repos) { + + r.setQueryMethod("POST"); + + // Should be empty. + assertEquals(0L, + countResults(r.prepareTupleQuery("SELECT * {?a ?b ?c}") + .evaluate())); + + } + + } + } Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepository.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepository.java 2014-03-13 16:21:32 UTC (rev 7956) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepository.java 2014-03-13 16:57:19 UTC (rev 7957) @@ -141,15 +141,28 @@ static protected final String UTF8 = "UTF-8"; /** - * Note: The default is <code>false</code>. This supports use cases where - * the end points are read/write databases and http caching must be defeated - * in order to gain access to the most recent committed state of the end - * point. + * The name of the system property that may be used to specify the default + * HTTP method (GET or POST) for a SPARQL QUERY or other indempotent + * request. * + * @see #DEFAULT_QUERY_METHOD + * + * @see <a href="http://trac.bigdata.com/ticket/854"> Allow overrride of + * maximum length before converting an HTTP GET to an HTTP POST </a> + */ + static public final String QUERY_METHOD = RemoteRepository.class + .getName() + ".queryMethod"; + + /** + * Note: The default is {@value #DEFAULT_QUERY_METHOD}. This supports use + * cases where the end points are read/write databases and http caching must + * be defeated in order to gain access to the most recent committed state of + * the end point. + * * @see #getQueryMethod() * @see #setQueryMethod(String) */ - static private final String DEFAULT_QUERY_METHOD = "POST"; + static public final String DEFAULT_QUERY_METHOD = "POST"; /** * The name of the system property that may be used to specify the maximum @@ -159,7 +172,8 @@ * @see <a href="http://trac.bigdata.com/ticket/854"> Allow overrride of * maximum length before converting an HTTP GET to an HTTP POST </a> */ - static public final String MAX_REQUEST_URL_LENGTH = "maxRequestURLLength"; + static public final String MAX_REQUEST_URL_LENGTH = RemoteRepository.class + .getName() + ".maxRequestURLLength"; /** * The default maximum limit on a requestURL before the request is converted @@ -192,15 +206,13 @@ * The maximum requestURL length before the request is converted into a POST * using a <code>application/x-www-form-urlencoded</code> request entity. */ - private volatile int maxRequestURLLength = Integer.parseInt(System - .getProperty(MAX_REQUEST_URL_LENGTH, - Integer.toString(DEFAULT_MAX_REQUEST_URL_LENGTH))); + private volatile int maxRequestURLLength; /** * The HTTP verb that will be used for a QUERY (versus a UPDATE or other * mutation operation). */ - private volatile String queryMethod = DEFAULT_QUERY_METHOD; + private volatile String queryMethod; /** * Return the maximum requestURL length before the request is converted into @@ -228,7 +240,7 @@ /** * Return the HTTP verb that will be used for a QUERY (versus an UPDATE or - * other mutation operations) (default {@value #DEFAULT_IS_GET}). POST can + * other mutation operations) (default {@value #DEFAULT_QUERY_METHOD}). POST can * often handle larger queries than GET due to limits at the HTTP client * layer and will defeat http caching and thus provide a current view of the * committed state of the SPARQL end point when the end point is a @@ -312,6 +324,12 @@ this.executor = executor; + setMaxRequestURLLength(Integer.parseInt(System.getProperty( + MAX_REQUEST_URL_LENGTH, + Integer.toString(DEFAULT_MAX_REQUEST_URL_LENGTH)))); + + setQueryMethod(System.getProperty(QUERY_METHOD, DEFAULT_QUERY_METHOD)); + } @Override @@ -971,7 +989,7 @@ */ protected void setupConnectOptions() { - opts.method = "POST"; + opts.method = getQueryMethod(); if(update) { Modified: branches/RDR/bigdata-jini/src/test/com/bigdata/journal/jini/ha/TestHA3JournalServer.java =================================================================== --- branches/RDR/bigdata-jini/src/test/com/bigdata/journal/jini/ha/TestHA3JournalServer.java 2014-03-13 16:21:32 UTC (rev 7956) +++ branches/RDR/bigdata-jini/src/test/com/bigdata/journal/jini/ha/TestHA3JournalServer.java 2014-03-13 16:57:19 UTC (rev 7957) @@ -3477,4 +3477,65 @@ } } + /** + * Test verifies that we can POST a SPARQL query to a follower. + * + * @see <a href="http://trac.bigdata.com/ticket/853"> Follower does not + * accept POST of idempotent operations (HA) </a> + */ + public void test_postQueryOnFollowers() throws Exception { + + final ABC abc = new ABC(false/*sequential*/); // simultaneous start. + + final HAGlue serverA = abc.serverA, serverB = abc.serverB, serverC = abc.serverC; + + // Verify quorum is FULLY met. + awaitFullyMetQuorum(); + + // await the KB create commit point to become visible on each service. + awaitCommitCounter(1L, new HAGlue[] { serverA, serverB, serverC }); + + // Verify binary equality of ALL journals. + assertDigestsEquals(new HAGlue[] { serverA, serverB, serverC }); + + final RemoteRepository[] repos = new RemoteRepository[3]; + repos[0] = getRemoteRepository(serverA); + repos[1] = getRemoteRepository(serverB); + repos[2] = getRemoteRepository(serverC); + + /* + * Verify that query on all nodes is allowed. + */ + for (RemoteRepository r : repos) { + + r.setQueryMethod("GET"); + + // Should be empty. + assertEquals(0L, + countResults(r.prepareTupleQuery("SELECT * {?a ?b ?c}") + .evaluate())); + + } + + // Change the maximum length of a GET for a Query. + for(RemoteRepository r : repos) { + + r.setMaxRequestURLLength(1); + + } + + // Run with the new length. All requests should be POSTs. + for (RemoteRepository r : repos) { + + r.setQueryMethod("POST"); + + // Should be empty. + assertEquals(0L, + countResults(r.prepareTupleQuery("SELECT * {?a ?b ?c}") + .evaluate())); + + } + + } + } Modified: branches/RDR/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepository.java =================================================================== --- branches/RDR/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepository.java 2014-03-13 16:21:32 UTC (rev 7956) +++ branches/RDR/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepository.java 2014-03-13 16:57:19 UTC (rev 7957) @@ -141,15 +141,28 @@ static protected final String UTF8 = "UTF-8"; /** - * Note: The default is <code>false</code>. This supports use cases where - * the end points are read/write databases and http caching must be defeated - * in order to gain access to the most recent committed state of the end - * point. + * The name of the system property that may be used to specify the default + * HTTP method (GET or POST) for a SPARQL QUERY or other indempotent + * request. * + * @see #DEFAULT_QUERY_METHOD + * + * @see <a href="http://trac.bigdata.com/ticket/854"> Allow overrride of + * maximum length before converting an HTTP GET to an HTTP POST </a> + */ + static public final String QUERY_METHOD = RemoteRepository.class + .getName() + ".queryMethod"; + + /** + * Note: The default is {@value #DEFAULT_QUERY_METHOD}. This supports use + * cases where the end points are read/write databases and http caching must + * be defeated in order to gain access to the most recent committed state of + * the end point. + * * @see #getQueryMethod() * @see #setQueryMethod(String) */ - static private final String DEFAULT_QUERY_METHOD = "POST"; + static public final String DEFAULT_QUERY_METHOD = "POST"; /** * The name of the system property that may be used to specify the maximum @@ -159,7 +172,8 @@ * @see <a href="http://trac.bigdata.com/ticket/854"> Allow overrride of * maximum length before converting an HTTP GET to an HTTP POST </a> */ - static public final String MAX_REQUEST_URL_LENGTH = "maxRequestURLLength"; + static public final String MAX_REQUEST_URL_LENGTH = RemoteRepository.class + .getName() + ".maxRequestURLLength"; /** * The default maximum limit on a requestURL before the request is converted @@ -192,15 +206,13 @@ * The maximum requestURL length before the request is converted into a POST * using a <code>application/x-www-form-urlencoded</code> request entity. */ - private volatile int maxRequestURLLength = Integer.parseInt(System - .getProperty(MAX_REQUEST_URL_LENGTH, - Integer.toString(DEFAULT_MAX_REQUEST_URL_LENGTH))); + private volatile int maxRequestURLLength; /** * The HTTP verb that will be used for a QUERY (versus a UPDATE or other * mutation operation). */ - private volatile String queryMethod = DEFAULT_QUERY_METHOD; + private volatile String queryMethod; /** * Return the maximum requestURL length before the request is converted into @@ -228,7 +240,7 @@ /** * Return the HTTP verb that will be used for a QUERY (versus an UPDATE or - * other mutation operations) (default {@value #DEFAULT_IS_GET}). POST can + * other mutation operations) (default {@value #DEFAULT_QUERY_METHOD}). POST can * often handle larger queries than GET due to limits at the HTTP client * layer and will defeat http caching and thus provide a current view of the * committed state of the SPARQL end point when the end point is a @@ -312,6 +324,12 @@ this.executor = executor; + setMaxRequestURLLength(Integer.parseInt(System.getProperty( + MAX_REQUEST_URL_LENGTH, + Integer.toString(DEFAULT_MAX_REQUEST_URL_LENGTH)))); + + setQueryMethod(System.getProperty(QUERY_METHOD, DEFAULT_QUERY_METHOD)); + } @Override @@ -1017,7 +1035,7 @@ */ protected void setupConnectOptions() { - opts.method = "POST"; + opts.method = getQueryMethod(); if(update) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |