Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Motivation

When processing data, the user wants users want to have access to client attributes - an associative array specified on the client an application side. Usage scenarios:

...

Code Block
languagejava
/** SessionContext interface. It's an entrypoint for all non-tabular information. */
public class SessionContext {
    /** @return Client attributes set for current thread. */
    public static @Nullable Map<String, String> getClientAttributes();
 }
 
/** Example, use it in QuerySqlFunction. */
public static class UserDefinedFunctions {
    /** @return Session ID, client attribute. */
    @QuerySqlFunction
    public static String sessionId() {
        Map<String, String> clnAttrs = SessionContext.getClientAttributes();
 
        return clnAttrs == null ? null : clnInfo.getProperty(SESSION_ID);
    }
}

SessionContext can be further extended to retrieve other non-tabular information, such as SecuritySubject, Transaction, ServiceCallContext, etc.

Setting attributes

JDBC

The standard jdbc protocol describes the methods Connection#setClientInfo, which allow changing the values ​​of client attributes during the life of the connection [3]. Implementation features:

  1. The list of attributes that can be set using #setClientInfo is arbitrary. The documentation recommends strictly limiting the set of attributes, but this is not necessary. For example, Oracle does not have such a limitation [5]. The setClientInfo array is completely translated into the getClientAttributes array.
  2. The parameters set in setClientInfo are passed along with each JdbcRequest (this requires a new feature in JdbcThinFeature).
  3. The client must reset the set values ​​itself.

Ignite 

Same as IgniteClient - attach the attributes to transaction:

Code Block
languagejava
// Extends the interface with new public method.
public interface IgniteTransactions {
 	...

    /** @param clnAttrs Client attributes. */
    public IgniteTransactions withClientAttributes(Map<String, String> clnAttrs);
}

// Example of usage.
try (Ignite ign = Ignition.localIgnite()) {
     Map<String, String> clnAttrs = F.asMap("SESSION_ID", "1234");
 
     try (Transaction tx = ign.transactions().withClientAttributes(clnAttrs).txStart(
Code Block
languagejava
// JDBC connection to Ignite server.
try (Connection conn = DriverManager.getConnection(URL)) {
    conn.setClientInfo    clnAttrs.setAttribute("SESSION_ID", "1234");
 
        ...
    }

}

IgniteClient (Java)

Implementation features:

...

Code Block
languagejava
// Extends the interface with new public method.
public interface ClientTransactions {
	...

    /** @param clnAttrs Client attributes. */
    public ClientTransactions withClientAttributes(Map<String, String> clnAttrs);
}

// Example of usage.
try (IgniteClient cln = Ignition.startClient(clnCfg)) {
    Map<String, String> clnAttrs = F.asMap("SESSION_ID", "1234");

    try (ClientTransaction tx = cln.transactions().withClientAttributes(clnAttrs).txStart()) {
        ...
    }
}

Ignite 

Same as IgniteClient - attach the attributes to transaction:

JDBC

The standard jdbc protocol describes the methods Connection#setClientInfo, which allow changing the values ​​of client attributes during the life of the connection [3]. Implementation features:

  1. The list of attributes that can be set using #setClientInfo is arbitrary. The documentation recommends strictly limiting the set of attributes, but this is not necessary. For example, Oracle does not have such a limitation [5]. The setClientInfo array is completely translated into the getClientAttributes array.
  2. The parameters set in setClientInfo are passed along with each JdbcRequest (this requires a new feature in JdbcThinFeature).
  3. The client must reset the set values ​​itself.


Code Block
languagejava
// ExtendsJDBC theconnection interface with new public method.
public interface IgniteTransactions {
 	...

    /** @param clnAttrs Client attributes. */
    public IgniteTransactions withClientAttributes(Map<String, String> clnAttrs);
}

// Example of usage.
try (Ignite ign = Ignition.localIgnite()) {
     Map<String, String> clnAttrs = F.asMap("SESSION_ID", "1234");
 
     try (Transaction tx = ign.transactions().withClientAttributes(clnAttrs).txStart(to Ignite server.
try (Connection conn = DriverManager.getConnection(URL)) {
        clnAttrs.setAttributeconn.setClientInfo("SESSION_ID", "1234");
 
        ...
    }
}

Spreading context across cluster nodes

...