Tuesday, December 20, 2016

Getting Start with MySQL Community Server ZIP Archive on Windows

It's always easy to use a zip archive than installing a software on your machine. Recently I've got to use MySQL Community Server ZIP Archive (mysql-5.7.17) and faced some problem when setting up the server. I will give you few step by step guidelines for a successful set up so that you won't face the same problems.

Step 1: Extract the zip archive.
Lets say the base directory path is D:\mysql-server

Step 2: Open the command prompt in Administrator Mode and navigate to MySQL base directory.
This is the most important step. MySQL needs access to your registry at the initial execution. If you execute the initial MySQL commands without administrator mode you will get an error message like follows.
Could not create or access the registry key needed for the MySQL application
to log to the Windows EventLog. Run the application with sufficient
privileges once to create the key, add the key manually, or turn off
logging for that application.

Step 3: Enter following commands.
D:\mysql-server> mysqld --initialize
D:\mysql-server>mysqld --initialize-insecure

Above first command will create a random password for root user account while second won't.

Setp 4: Enter mysqld in the command prompt.
D:\mysql-server> mysqld
Now your MySQL server is up and running!

Using command prompt in administrator mode is only for the setting up. You don't want administrator mode in the later sever startups.

A Note for MySQL Workbench Users:
I use MySQL Workbench as the IDE. My OS is a 64bit OS and I downloaded 64bit non-install zip version of MySQL Workbench. But it got crashed when i started it. Then i browsed internet and found that 32bit version is the solution. I downloaded MySQL Workbench 32 bit non-install zip and it worked fine.

Thursday, January 28, 2016

Find Eclipse IDE Information - Eclipse Plugin Development

This simple Eclipse plugin program shows you how to retrieve following information regarding the Eclipse IDE.
  • IDE name
  • IDE version (.., Kepler, Luna, Mars,..etc with version number) 
  • Plugin version
  • Platform user name

You can test the program by running it your RCP environment. When you ran it, click on the LakJ Comspace icon in the tool bar of Eclipse sandbox window. Then you will see the information.
Following is the java code related to the program. You can download the complete project from the github links given at the end of the tutorial.

Here the InfoUtil.java does the information retrieving. Rest of the two classes (Activator and InfoAction) help the program to behave as a Eclipse plugin.

Following are the GitHub URL's for complete plugin project. You can clone the project or downolad the project as a zip file. To run the project open an Eclipse RCP environment and import the project as a maven project.

GitHub repository URL - https://github.com/lakjcomspace/Eclipse-Find-IDE-Info
GitHub HTTPS clone URL - https://github.com/lakjcomspace/Eclipse-Find-IDE-Info.git
Download Project as a Zip - https://github.com/lakjcomspace/Eclipse-Find-IDE-Info/archive/master.zip

Tuesday, November 24, 2015

OrientDB - Using plocal Embedded Storage from Two Processes

OrientDB has this nice feature of creating and using database in embedded mode. We can programatically create and accesses OrientDB database for CRUD operations without the server. We can create a plocal storage (Paginated Local Storage) with this. plocal is a disk based storage which works with data using page model. This storage is very fast because of we can assess the database directly with local mode.

But, plocal storage has a limitation; it can only be accessed by one process at a time. When a process accesses the database, it locks the database so that no other program or process can access that. This lock will not be released until the program terminates. It avoids updating the database from several processes.
If you are going to accesses the plocal db while another process has acquired the lock, you will have the following error message.

com.orientechnologies.orient.core.exception.OStorageException: Cannot open local storage 'C:/MyOrientDb/dbs/myPlocal' with mode=rw
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.open(OAbstractPaginatedStorage.java:217)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.open(ODatabaseDocumentTx.java:243)
at com.lakj.comspace.orientdb.PlocalTest.readDb(PlocalTest.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)...
Caused by: com.orientechnologies.orient.core.exception.OSerializationException: Cannot load database's configuration. The database seems to be corrupted.
at com.orientechnologies.orient.core.storage.impl.local.OStorageConfigurationSegment.load(OStorageConfigurationSegment.java:86)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.open(OAbstractPaginatedStorage.java:164)
... 28 more
Caused by: java.io.IOException: The process cannot access the file because another process has locked a portion of the file
at java.io.RandomAccessFile.read0(Native Method)
at java.io.RandomAccessFile.read(Unknown Source)
at com.orientechnologies.orient.core.storage.fs.OAbstractFile.openChannel(OAbstractFile.java:641)
at com.orientechnologies.orient.core.storage.fs.OAbstractFile.open(OAbstractFile.java:144)
at com.orientechnologies.orient.core.storage.impl.local.OSingleFileSegment.open(OSingleFileSegment.java:57)
at com.orientechnologies.orient.core.storage.impl.local.OStorageConfigurationSegment.load(OStorageConfigurationSegment.java:65)
... 29 more

 I found a solution to this problem!

When you want to share a plocal database among two (or more) processes, you can follow the following procedure.

Let's take a sample scenario. Two processes called Process-A and Process-B are going to access the same plocal storage named 'myPlocal'. Process-A reads the database. Then Process-B update the database and terminates. Then again Process-A reads the database.

Step 1:
Create the db connection from Process-A read the relevant data.
When the Process-A creates the db connection, it locks the db so that any other process cannot read or update the db.
ODatabaseDocumentTx dbProsA = new ODatabaseDocumentTx("plocal:/db/myPlocal");
dbProsA .open("admin", "admin");
Step 2:
Freeze the db from the Process-A.

Freeze method is used to create 'live' database backups. It flushes all cached content to the disk storage and allows to perform only read commands for current process. Here when the Process-A calls freeze method, no any thread from Process-A can write on db. But any thread from Process-A can read from db. More importantly, another process can acquire the db lock and update it. Here the Process-B will do it.
dbProsA .freeze();
Step 3:
Create the db connection from Process-B and read or update data. Then the Process-B terminates.
Because of Process-A has freezed it's connection Process-B can create a new connection and update the db. Here the Process-B should terminate and release the db so that the Process-A can get it back.
ODatabaseDocumentTx dbProsB = new ODatabaseDocumentTx("plocal:/db/myPlocal");
dbProsB.open("admin", "admin");
// Do whatever you want here 
Step 4:
Process-A release the db.
If you freeze the db connection, you should call release method to enable it for write operations.
dbProsA .release();
Step 5:
Process-A restarts the db engine.

This is the most important step. Though you have release the db connection from Process-A, it won't be able to read the updates which has been done by Process-B. You may still read the data which you had at the point you freeze it.
To read the updated values from the Process-B you should re-start the db engine from Process-A. It's just two method calls; shutdown() and start().
OOrient instance = Orient.instance();
You are done..!
Now you have shared your plocal db between Process-A and Process-B.