Solutions

Stay on top of everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up

Learn

Stay on top of everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up

Community

Stay on top of everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up

Company

Stay on top of everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up

 
Knowledgebase:
URI Keys
04 June 2015 07:14 PM

Summary

Internally, MarkLogic Server maps URIs to hash values. Hash values are just numbers.  For internal operations, numbers are easier to process and are more performant than strings. We refer the URI hash as a URI Key.   

Details

Where would I see a URI key?

Sometimes, URI Keys will appear in the MarkLogic Error Logs.  For example, the MarkLogic Lock Manager manages document locks. Internally, the lock manager in each forest doesn't deal with URIs, it only deals with URI keys. When logging messages, the lock manager helpfully tries to turn the URI key into a URI to be more human readable. It does that by looking up and retrieving the document URI matching that URI key.  If the reporting forest doesn't have a document to match the URI key, it will reports a URI key instead of a URI.

For example, if the 'Lock Trace' trace event is enabled, you may see events logged that look like either of the following lines:

2015-03-18 01:53:17.576 Info: [Event:id=Lock Trace] forest=content-f1 uri=/cache/151516917/state.xml waiting=11744114292967458924 holding=15120765280191786041

2015-03-18 01:53:17.576 Info: [Event:id=Lock Trace] forest=content-f1 uri=#7734249069814007397 waiting=11744114292967458924 holding=15120765280191786041

The first line shows a URI (/cache/151516917/state.xml), and the second gives instead a URI key (7734249069814007397). When a URI key is reported as in this example, one of the following 2 will be true:

  • The reporting action may be restricted to a single forest and the referenced document for the URI (key) may be in a different forest; or
  • The document may not exist at all. An example where this might occur is when a Lock is acquired by an update before the document is actually inserted, or xdmp:lock-for-update can lock URIs that aren’t in the database without ever creating a document.

How can I find a URI key for a URI?

To can turn a URI ($uri) into a URI key using the following XQuery code

xdmp:add64(xdmp:mul64(xdmp:hash64($uri),5),xdmp:hash64("uri()") 

You may want to generate the URI key in order to scan an Error Log file for reference to that key.

How can I find the URI or document for a URI key?

You can check the entire database by using cts:uris with a cts:term-query and that URI key.  As an example, the following XQuery code

xquery version '1.0-ml';
let $uri := '/foo.xml'
let $uri-key := xdmp:add64(xdmp:mul64(xdmp:hash64($uri),5),xdmp:hash64("uri()"))
return cts:uris ((), (), cts:term-query ($uri-key))

returns /foo.xml

 

(3 vote(s))
Helpful
Not helpful

Comments (0)