Skip to content

Transactions with runtime database does not work #171

@sravanr

Description

@sravanr

I see transactions getting commited with bulk write and runtime database selection, here is my code

setup:
setupJavaRESTServer(dbName, fNames[0], restServerName,restPort,false);
createUserRolesWithPrevilages("test-eval","xdbc:eval", "xdbc:eval-in","xdmp:eval-in","any-uri","xdbc:invoke");
createRESTUser("eval-user", "x", "test-eval","rest-admin","rest-writer","rest-reader");

client = DatabaseClientFactory.newClient("localhost", restPort,dbName,"eval-user", "x", Authentication.DIGEST);

@Test
    public void test2XqueryEvalTransactions() throws Exception{
        int count=1;
        boolean tstatus =true;
        Transaction t1 = client.openTransaction();
        try{ 
        XMLDocumentManager docMgr = client.newXMLDocumentManager();
        HashMap<String,String> map= new HashMap<String,String>();
        DocumentWriteSet writeset =docMgr.newWriteSet();
        for(int i =0;i<2;i++){
            writeset.add("/sec"+i+".xml", new DOMHandle(getDocumentContent("This is so sec"+i)));
            map.put("/sec"+i+".xml", convertXMLDocumentToString(getDocumentContent("This is so sec"+i)));
            if(count%100 == 0){
                docMgr.write(writeset,t1);
                writeset = docMgr.newWriteSet();
            }
            count++;
        }
        if(count%100 > 0){
            docMgr.write(writeset,t1);
        }
         String query = "declare variable $myInteger as xs:integer external;"
                    + "(fn:count(fn:doc()))";
         ServerEvaluationCall evl= client.newServerEval().xquery(query);
         EvalResultIterator evr = evl.eval();
         assertEquals("Count of documents outside of the transaction",1,evr.next().getNumber().intValue());
         evl= client.newServerEval().xquery(query).transaction(t1);
         evr = evl.eval();
         assertEquals("Count of documents outside of the transaction",103,evr.next().getNumber().intValue());
        }catch(Exception e){
            System.out.println(e.getMessage());
            tstatus=true;
            throw e;
        }finally{
            if(tstatus){
                t1.rollback();
            }
        }
}


Here the HTTP wire

In setup
14:35:15.608 [main] DEBUG c.m.client.DatabaseClientFactory - Creating new database client for server at localhost:8011
14:35:15.659 [main] DEBUG c.m.client.impl.JerseyServices - Connecting to localhost at 8011 as eval-user
14:35:16.561 [main] DEBUG c.m.client.impl.JerseyServices - Opening transaction
[DEBUG] wire - >> "POST /v1/transactions HTTP/1.1[\r][\n]"
[DEBUG] wire - >> "Content-Length: 0[\r][\n]"
[DEBUG] wire - >> "Host: localhost:8011[\r][\n]"
[DEBUG] wire - >> "Connection: Keep-Alive[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - << "HTTP/1.1 401 Unauthorized[\r][\n]"
[DEBUG] wire - << "WWW-Authenticate: Digest realm="public", qop="auth", nonce="7dfd22bbf46922f8ea13930bacbed826", opaque="ad00eb35d73ba934"[\r][\n]"
[DEBUG] wire - << "Content-Type: application/json; charset=utf-8[\r][\n]"
[DEBUG] wire - << "Server: MarkLogic[\r][\n]"
[DEBUG] wire - << "Content-Length: 104[\r][\n]"
[DEBUG] wire - << "Connection: Keep-Alive[\r][\n]"
[DEBUG] wire - << "Keep-Alive: timeout=5[\r][\n]"
[DEBUG] wire - << "[\r][\n]"
[DEBUG] wire - << "{"errorResponse":   {"statusCode":401,[\n]"
[DEBUG] wire - << "   "status":"Unauthorized",[\n]"
[DEBUG] wire - << "   "message":"401 Unauthorized"[\n]"
[DEBUG] wire - << "  }[\n]"
[DEBUG] wire - << "}"
[DEBUG] wire - >> "POST /v1/transactions HTTP/1.1[\r][\n]"
[DEBUG] wire - >> "Authorization: Digest username="eval-user",realm="public",nonce="7dfd22bbf46922f8ea13930bacbed826",opaque="ad00eb35d73ba934",qop=auth,uri="/v1/transactions",cnonce="c9f8711f",nc=00000001,response="12f3554b65cb06be63104291763a361e"[\r][\n]"
[DEBUG] wire - >> "Content-Length: 0[\r][\n]"
[DEBUG] wire - >> "Host: localhost:8011[\r][\n]"
[DEBUG] wire - >> "Connection: Keep-Alive[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - << "HTTP/1.1 303 See Created Transaction[\r][\n]"
[DEBUG] wire - << "Set-Cookie: HostId=2119842460509749647[\r][\n]"
[DEBUG] wire - << "Location: /v1/transactions/14038291096176634785[\r][\n]"
[DEBUG] wire - << "Server: MarkLogic[\r][\n]"
[DEBUG] wire - << "Content-Length: 0[\r][\n]"
[DEBUG] wire - << "Connection: Keep-Alive[\r][\n]"
[DEBUG] wire - << "Keep-Alive: timeout=5[\r][\n]"
[DEBUG] wire - << "[\r][\n]"
14:35:19.411 [main] DEBUG c.m.client.impl.JerseyServices - Posting multipart for documents
[DEBUG] wire - >> "POST /v1/documents?txid=14038291096176634785&database=TestEvalXqueryWithTransDB HTTP/1.1[\r][\n]"
[DEBUG] wire - >> "Content-Type: multipart/mixed; boundary=Boundary_1_1934785516_1415054119406[\r][\n]"
[DEBUG] wire - >> "Authorization: Digest username="eval-user",realm="public",nonce="7dfd22bbf46922f8ea13930bacbed826",opaque="ad00eb35d73ba934",qop=auth,uri="/v1/documents",cnonce="08c1cefa",nc=00000002,response="ab6586c2c232873f937b8259aa409a1f"[\r][\n]"
[DEBUG] wire - >> "Transfer-Encoding: chunked[\r][\n]"
[DEBUG] wire - >> "Host: localhost:8011[\r][\n]"
[DEBUG] wire - >> "Connection: Keep-Alive[\r][\n]"
[DEBUG] wire - >> "Cookie: HostId=2119842460509749647[\r][\n]"
[DEBUG] wire - >> "Cookie2: $Version=1[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - >> "7f[\r][\n]"
[DEBUG] wire - >> "--Boundary_1_1934785516_1415054119406[\r][\n]"
[DEBUG] wire - >> "Content-Disposition: attachment; filename="/sec0.xml"[\r][\n]"
[DEBUG] wire - >> "Content-Type: application/xml[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
14:35:19.431 [main] INFO  com.marklogic.client.io.DOMHandle - Serializing DOM document to output stream
[DEBUG] wire - >> "41[\r][\n]"
[DEBUG] wire - >> "<?xml version="1.0" encoding="UTF-8"?>[\n]"
[DEBUG] wire - >> "<foo>This is so sec0</foo>"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - >> "81[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - >> "--Boundary_1_1934785516_1415054119406[\r][\n]"
[DEBUG] wire - >> "Content-Disposition: attachment; filename="/sec1.xml"[\r][\n]"
[DEBUG] wire - >> "Content-Type: application/xml[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
14:35:19.513 [main] INFO  com.marklogic.client.io.DOMHandle - Serializing DOM document to output stream
[DEBUG] wire - >> "41[\r][\n]"
[DEBUG] wire - >> "<?xml version="1.0" encoding="UTF-8"?>[\n]"
[DEBUG] wire - >> "<foo>This is so sec1</foo>"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - >> "2b[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - >> "--Boundary_1_1934785516_1415054119406--[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - >> "0[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - << "HTTP/1.1 200 Bulk Change Written[\r][\n]"
[DEBUG] wire - << "vnd.marklogic.document-format: xml[\r][\n]"
[DEBUG] wire - << "Content-type: application/xml; charset=utf-8[\r][\n]"
[DEBUG] wire - << "Server: MarkLogic[\r][\n]"
[DEBUG] wire - << "Content-Length: 449[\r][\n]"
[DEBUG] wire - << "Connection: Keep-Alive[\r][\n]"
[DEBUG] wire - << "Keep-Alive: timeout=5[\r][\n]"
[DEBUG] wire - << "[\r][\n]"
[DEBUG] wire - << "<rapi:documents xmlns:rapi="http://marklogic.com/rest-api"><rapi:document><rapi:uri>/sec0.xml</rapi:uri><rapi:category>metadata</rapi:category><rapi:category>content</rapi:category><rapi:mime-type>application/xml</rapi:mime-type></rapi:document><rapi:document><rapi:uri>/sec1.xml</rapi:uri><rapi:category>metadata</rapi:category><rapi:category>content</rapi:category><rapi:mime-type>application/xml</rapi:mime-type></rapi:document></rapi:documents>[\n]"
14:35:21.523 [main] DEBUG c.m.client.impl.JerseyServices - Posting eval
[DEBUG] wire - >> "POST /v1/eval?database=TestEvalXqueryWithTransDB HTTP/1.1[\r][\n]"
[DEBUG] wire - >> "Content-Type: application/x-www-form-urlencoded[\r][\n]"
[DEBUG] wire - >> "Accept: multipart/mixed; boundary=Boundary_2_78631448_1415054121523[\r][\n]"
[DEBUG] wire - >> "Authorization: Digest username="eval-user",realm="public",nonce="7dfd22bbf46922f8ea13930bacbed826",opaque="ad00eb35d73ba934",qop=auth,uri="/v1/eval",cnonce="1c5e941e",nc=00000003,response="9c26070335c11f46e9f1635ddeff02c7"[\r][\n]"
[DEBUG] wire - >> "Transfer-Encoding: chunked[\r][\n]"
[DEBUG] wire - >> "Host: localhost:8011[\r][\n]"
[DEBUG] wire - >> "Connection: Keep-Alive[\r][\n]"
[DEBUG] wire - >> "Cookie: HostId=2119842460509749647[\r][\n]"
[DEBUG] wire - >> "Cookie2: $Version=1[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - >> "64[\r][\n]"
[DEBUG] wire - >> "xquery=declare+variable+%24myInteger+as+xs%3Ainteger+external%3B%28fn%3Acount%28fn%3Adoc%28%29%29%29"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - >> "0[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - << "HTTP/1.1 200 OK[\r][\n]"
[DEBUG] wire - << "Server: MarkLogic 8.0-20141030[\r][\n]"
[DEBUG] wire - << "Set-Cookie: TxnMode=auto; path=/[\r][\n]"
[DEBUG] wire - << "Set-Cookie: TxnID=null; path=/[\r][\n]"
[DEBUG] wire - << "Content-Type: multipart/mixed; boundary=55510e4599538c39[\r][\n]"
[DEBUG] wire - << "Content-Length: 97[\r][\n]"
[DEBUG] wire - << "Connection: Keep-Alive[\r][\n]"
[DEBUG] wire - << "Keep-Alive: timeout=5[\r][\n]"
[DEBUG] wire - << "[\r][\n]"
[DEBUG] wire - << "[\r][\n]"
[DEBUG] wire - << "--55510e4599538c39[\r][\n]"
[DEBUG] wire - << "Content-Type: text/plain[\r][\n]"
[DEBUG] wire - << "X-Primitive: integer[\r][\n]"
[DEBUG] wire - << "[\r][\n]"
[DEBUG] wire - << "2[\r][\n]"
[DEBUG] wire - << "--55510e4599538c39--[\r][\n]"
14:35:21.578 [main] DEBUG c.m.client.impl.JerseyServices - Completing transaction 14038291096176634785 with rollback
[DEBUG] wire - >> "POST /v1/transactions/14038291096176634785?result=rollback HTTP/1.1[\r][\n]"
[DEBUG] wire - >> "Authorization: Digest username="eval-user",realm="public",nonce="7dfd22bbf46922f8ea13930bacbed826",opaque="ad00eb35d73ba934",qop=auth,uri="/v1/transactions/14038291096176634785",cnonce="b8e74510",nc=00000004,response="4be33913615d2205e232c77599db29d4"[\r][\n]"
[DEBUG] wire - >> "Content-Length: 0[\r][\n]"
[DEBUG] wire - >> "Host: localhost:8011[\r][\n]"
[DEBUG] wire - >> "Connection: Keep-Alive[\r][\n]"
[DEBUG] wire - >> "Cookie: HostId=2119842460509749647; TxnID=null; TxnMode=auto[\r][\n]"
[DEBUG] wire - >> "Cookie2: $Version=1[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - << "HTTP/1.1 204 Rolled Back[\r][\n]"
[DEBUG] wire - << "Server: MarkLogic[\r][\n]"
[DEBUG] wire - << "Content-Length: 0[\r][\n]"
[DEBUG] wire - << "Connection: Keep-Alive[\r][\n]"
[DEBUG] wire - << "Keep-Alive: timeout=5[\r][\n]"
[DEBUG] wire - << "[\r][\n]"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions