2008年12月17日水曜日

[Grails]Integration Terracotta(Java VM Clustering) with Grails manually

Steps to Integrate the Terracotta(Java VM Clustering) with Grails manually without using the Terracotta plugin.
  • References
  • Steps
    • Install Java development kit
    • Install latest grails
    • Install latest terracotta
    • Create terracotta's config file as follows
      (Following is a example configuration, please refer to the terracotta documentation about the detail of the config file)
      Following configuration is clustered the util.cache.Cache.cacheMap object, and set the named-lock for all the methods.
      <?xml version="1.0" encoding="UTF-8"?>
      <tc:tc-config xmlns:tc="http://www.terracotta.org/config"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-4.xsd">

      <servers>
      <server name="server1" host="localhost">
      <data>%(user.home)/terracotta/server-data</data>
      <logs>%(user.home)/terracotta/server-logs</logs>
      <dso>
      <client-reconnect-window>10</client-reconnect-window>
      <persistence>
      <mode>temporary-swap-only</mode>
      </persistence>
      <garbage-collection>
      <enabled>true</enabled>
      <verbose>false</verbose>
      <interval>180</interval>
      </garbage-collection>
      </dso>
      <jmx-port>9520</jmx-port>
      <l2-group-port>9530</l2-group-port>
      </server>
      </servers>

      <clients>
      <logs>%(user.home)/terracotta/client-logs</logs>
      </clients>

      <application>
      <dso>
      <roots>
      <root>
      <field-name>util.cache.Cache.cacheMap</field-name>
      </root>
      </roots>

      <instrumented-classes>
      <include>
      <class-expression>util.cache.Cache</class-expression>
      </include>
      </instrumented-classes>

      <locks>
      <named-lock>
      <lock-name>CacheMapWriteLock</lock-name>
      <lock-level>write</lock-level>
      <method-expression>* util.cache.Cache.clear(..)</method-expression>
      </named-lock>

      <named-lock>
      <lock-name>CacheMapWriteLock</lock-name>
      <lock-level>concurrent</lock-level>
      <method-expression>* util.cache.Cache.set(..)</method-expression>
      </named-lock>

      <named-lock>
      <lock-name>CacheMapWriteLock</lock-name>
      <lock-level>concurrent</lock-level>
      <method-expression>* util.cache.Cache.remove(..)</method-expression>
      </named-lock>

      <named-lock>
      <lock-name>CacheMapReadLock</lock-name>
      <lock-level>read</lock-level>
      <method-expression>* util.cache.Cache.get(..)</method-expression>
      </named-lock>

      <named-lock>
      <lock-name>CacheMapReadLock</lock-name>
      <lock-level>read</lock-level>
      <method-expression>* util.cache.Cache.contain(..)</method-expression>
      </named-lock>
      </locks>
      </dso>
      </application>
      </tc:tc-config>
    • Start the terracotta server
      ${TC_INSTALL_DIR}/bin/start-tc-server.sh -f (Set path to the terracotta config) -n (Set server name in terracotta config file)
    • Set the environment variables
      export JAVA_HOME=(Set JDK's home directory)
      export GRAILS_HOME=(Set Grails home directory)
      export JAVA_OPTS="(Set java option parameters if you need)"
      export TC_INSTALL_DIR=(Set Teraccotta's home directory)
      export JAVACMD="${TC_INSTALL_DIR}/bin/dso-java.sh"
      export JAVA_OPTS="$JAVA_OPTS -Dtc.config=(Set path to the terracotta config file)"
    • Start Grails web server
      grails -Dserver.port=(Set Port Number) run-app dev
      (When executing this command, jetty is started after grails command run the terracotta client and read the configration file because the JAVACMD environment variable is set to the terracotta shell script file)
    • Integration terracotta with the tomcat
      Please refer to the terracotta documentation for more detail.
      http://www.terracotta.org/web/display/orgsite/Tomcat+Integration

      Following is a sample tomcat startup script.
      JAVA_HOME="(top directory name installed the jdk)"
      JAVA_OPTS="-server -Xms256m -Xmx512m -Xss256k"
      TOMCAT_HOME="(top directory name installed the tomcat)"
      PATH="$PATH:$JAVA_HOME/bin:$ANT_HOME/bin:$TOMCAT_HOME/bin"

      TC_INSTALL_DIR="(directory name installed the terracotta)"
      TC_CONFIG_PATH="(full path name of the terracotta configuration file.)"
      . $TC_INSTALL_DIR/bin/dso-env.sh -q
      export JAVA_OPTS="$TC_JAVA_OPTS $JAVA_OPTS"
      sh ${TOMCAT_HOME}/bin/catalina.sh start
    • Integration terracotta with jetty
      Please refer to the terracotta documentation.
      http://www.terracotta.org/web/display/orgsite/Jetty+Integration

2008年12月15日月曜日

[Linux]yum process hangs and stacks without erroring out

  • References
    Yum hangs(http://www.windley.com/archives/2007/04/yum_hangs.shtml)
  • Description
    yum process sometimes hangs and stacks without erroring out. No error messages are outputted. I get the result of strace for the command "yum clear all" as follows.
    > strace -f -F yum clear all
    ......
    stat64("/var/lib/rpm/DB_CONFIG", 0xbf93281c) = -1 ENOENT (No such file or directory)
    open("/var/lib/rpm/DB_CONFIG", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
    stat64("/var/lib/rpm/__db.001", {st_mode=S_IFREG|0644, st_size=24576, ...}) = 0
    open("/var/lib/rpm/__db.001", O_RDWR|O_LARGEFILE) = 3
    fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
    fstat64(3, {st_mode=S_IFREG|0644, st_size=24576, ...}) = 0
    close(3) = 0
    open("/var/lib/rpm/__db.001", O_RDWR|O_LARGEFILE) = 3
    fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
    mmap2(NULL, 24576, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0) = 0xb7a17000
    close(3) = 0
    stat64("/var/lib/rpm/__db.002", {st_mode=S_IFREG|0644, st_size=1318912, ...}) = 0
    open("/var/lib/rpm/__db.002", O_RDWR|O_LARGEFILE) = 3
    fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
    mmap2(NULL, 1318912, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0) = 0xb78d5000
    close(3) = 0
    stat64("/var/lib/rpm/__db.003", {st_mode=S_IFREG|0644, st_size=450560, ...}) = 0
    open("/var/lib/rpm/__db.003", O_RDWR|O_LARGEFILE) = 3
    fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
    mmap2(NULL, 450560, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0) = 0xb7867000
    close(3) = 0
    stat64("/var/lib/rpm/Packages", {st_mode=S_IFREG|0644, st_size=19869696, ...}) = 0
    open("/var/lib/rpm/Packages", O_RDONLY|O_LARGEFILE) = 3
    fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
    read(3, "\0\0\0\0\1\0\0\0\0\0\0\0a\25\6\0\10\0\0\0\0\20\0\0\0\10"..., 512) = 512
    close(3) = 0
    open("/var/lib/rpm/Packages", O_RDONLY|O_LARGEFILE) = 3
    fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
    fstat64(3, {st_mode=S_IFREG|0644, st_size=19869696, ...}) = 0
    futex(0xb78c587c, FUTEX_WAIT, 1, NULL
  • Solution
    remove the __db.* files under the /var/lib/rpm and retry running the yum command.

2008年12月12日金曜日

[Grails]Split Write Database Connection Plugin for master/slave configuration(Alpha version 0.2)

Please refer to the
http://taapps-javalibs.blogspot.com/2009/04/grailsupgraded-split-write-database.html

Grails Split Write Database Connection Plugin for master-slave configuration (Alpha version 0.2, like the magic multi connection for rails framework, multiple datasource)

After installing this plugin, we can split the read/write database connection and write any data to the other database and System will inject new methods into the Domain Classes named like saveXXXXX, lockXXXXX, deleteXXXXX, executeUpdateXXXXX method to split writing the data to the other databases.

Refer to the http://groups.google.com/group/taapps-sourcecode-libraries/web/grails-split-write-database-connection-plugin

2008年12月8日月曜日

[GRAILS]how to use the String type for the primary key column

How to use the String type primary key column in Domain Class on Grails environment.
  • the definition of the Domain Class
    class Test {
    //define id column as String type
    String id
    .....
    //define the id generator type, it should use the manual assignment
    static mapping={
    id generator:'assigned'
    }
    }
  • using this domain class
            def index = {
    //create new object defined the primary key as the String type.
    def test=new Test()

    def date=new Date()
    //set the unique value of primary key manually.
    test.setId("pk-${date.getTime()}")
    test.setMsg("Message")
    //save
    test.save()
    ...
    }