Isolation Levels for Clients of a Service Provider System (Not necessarily a DBMS)

Isolation levels have been discussed mostly in the context of DBMS.  Abstracting this further to a generic system is this attempt…

 
Scenario:
  1. There are 3 systems: System1, System2 and System3.
  2. System1 encapsulates certain data and provides “primary” operation Op1, Op2, Op3 on that data (Variations of the operations are also provided by System1)
  3. System2 and System3 are consumers of that data.
  4. System2 and System3 access System1’s operations independent of each other.
  5. System1 doesnot perform any operations on the  data by itself.
  6. Data is always modified by through one of the operations Op1/Op2/Op3, executed by System1 when a request is raised for an operation. by System2 or System3.
Problem:
Given the above scenario:
  1. How does System2’s interaction with System1 impact System3’s interaction with System1 i.e. what isolation levels can be made available by System1 to offer to System2 and System
Approach:
  1. Assuming that every operation is important from the perspective of either seeker (ex: System2 ) or the provider (ex: System1)  each operation can be controlled by a counting semaphore (ex: binary semaphore which represents locked/unlocked state)
  2. Lets name these counting semaphores a Sem1, Sem2, Sem3.
  3. Lets also name the cardinality of the set of values each of the semaphores as  N1, N2 and N3 respectively.  As with a counting semaphore for resources, a value taken out of the set has to be returned to it before another client can be given that same value.
  4. Given above the access privileges of System2 (or System3), at a given point of time, on operations provided by System1 (ex: Op1) can be depicted by the value of the Semaphores that they hold. i.e.  System2 may hold a value x of Sem1 (among the N1 possible values) y of Sem2 and z of Sem3.
  5. Given above it is possible to write a function which determines whether a certain combination of  semaphores of a set of clients is valid ex: a function which takes as input – clients and their  semaphores  – returns a boolean flag indicating if the combination is valid for the semantics of the problem. For a more concrete example
    • if System1 is database and operation is “write”,  System2 and System3 cannot hold “locked” value for “write” semaphore. So this function would return false.
  6. By executing the above function for all combinations of semaphores for two concurrent clients, it should be possible to arrive at a list of valid combinations ex: if System1 is a database and primitive operations are read and write (insert, update and delete are different modes of this primitive operations) then several combinations are valid (as per the function which bases its judgement on the semantics of database management problem). For more concrete example below are valid combinations for System1(database)
    • System2 – Write – Locked and System3 – Read – Unlocked.
    • System2 – Read – Unlocked and System3 – Read – Unlocked
  7. Group the valid combinations into various isolation levels again based on the semantics of the problem ex: in case of database (or a caching implementation) the isolation level could be defined as below based on what the function considers as valid.
    • Read committed
    • Read Uncommitted
    • Serializable
    • Repeatable read

(Work-in-progress: how to write the function in a generic manner, such that with enough parameters it could return valid isolation levels for any Service Provider System)

REPL for Java

While JRubyBeanShellJulian Fleischer’s REPL are there Albert Latacz’s REPL seems to be the latest and active.

Tried it with a class definition (made the class look like this by design to try as many language elements as possible), works fine.

$ java -jar javarepl.jar
Welcome to JavaREPL version 56 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_17)
Type in expression to evaluate.
Type :help for more options.

java> public class Test {
    | public static void execute(String [] s) {
    |  System.out.println(54353 + s[0]);
    | }}

java> Test.execute(new String [] {"234343"});
54353234343

java> System.exit(0);

 References: [StackOverFlow]

Ruby and Java’s approach towards Reflection

As per http://docs.oracle.com/javase/tutorial/reflect/index.html, certain VM optimizations cannot be performed during reflection, also there are security concerns since private methods are made accessible. There are also synchronization concerns in some of the reflection apis ex: loading class is a synchronized operation. These reasons discouraged java developers from using the api unless its absolutely necessary.
 
While in ruby reflection seems to be a feature that’s used extensively, on-top of which meta-programming is made possible. ex: activerecord creates model’s attributes and their accessors on the fly.
 
While the overhead of reflection and possible erroneous scenarios in a multi-threaded environment have to be addressed, these two languages seem to have taken diametrically opposite stances on the subject.