Wednesday, August 17, 2016

SVN Branching – Best Practices

Background 

This blog is created to use a reference when you use SVN as the source control versioning system during development.  In this blog, I have documented the best practices on when to use trunk and when to create SVN branches during development to streamline the branching process.

Different folders under SVN repository

Sub version repository will always have below three different folders under the “project root”.  A repository can have one or more “project root”.

/trunk
/branches
/tags

Build and release from Trunk

In general circumstances, all the day-2-day development should happen under the trunk and the releases to Integration, QA, Staging and Production environments should happen from trunk

Trunk should compile and pass all the unit test cases at any point of the time. 

Developer should add the user story #’s or defect #’s into the comments section while check-in the code.

Every story/defect fix should have a separate commit, instead of having multiple fixes checked in under a single commit.  This will ease the process for the peer who does the code review. 

It’s the responsibility of the developer who check-in the code to make sure the code compiles all the time and all the automated unit test cases pass with the current code available in the trunk.

Creating branches

Ideally, SVN branches have to be created in any of the below three situations:

1. Hot fixes release to production

If there are any production hot fixes needs to be released, then a new branch has to be created using production build tag first.

The hot fixes have to be applied to that new branch and released to QA, Staging and Production environment.

Finally, the changes have to be merged back into trunk.

2. Projects running across multiple sprints

For the project(s) which runs in parallel and where development spans across multiple sprints, then a new branch has to be created for each project. 

It’s a good practice to setup multiple isolation environments in QA to verify only the project related changes which can be deployed from that branch.

Whenever any production release(s) happen from trunk, then the changes have to be merged from trunk back into the individual project branches created.

3. Additional fix on working trunk after build is finalized

Assume, trunk changes are finalized for a release (let’s say – build with tag-44) and next sprint changes are being checked into trunk (let’s say – build with tag-45, tag-46).  

Now, assume QA team identifies an issue which needs to be fixed in the current build which is finalized for the release. 

In this case, we can’t have the fix checked into trunk since we don’t need the changes which are tagged with tag-45 and tag-46 to be released to production. 

Hence, a new branch would be created from tag-44 and the additional fix would be applied on the branch, release to QA, Staging and Production from that branch. 

Later the changes have to be merged back into trunk.


Thursday, March 27, 2014

Cassandra running out of memory heap space

I have configured Cassandra 2.0.4 in my laptop which was working fine for few weeks.  My machine configuration is below -







On a day-2-day basis, I have been truncating the database and recreating frequently.  After few weeks, when I tried to start Cassandra, I started getting the below error - 

java.lang.OutOfMemoryError: Java heap space
at org.apache.cassandra.io.compress.CompressedRandomAccessReader.<init>(CompressedRandomAccessReader.java:64)
at org.apache.cassandra.io.compress.CompressedRandomAccessReader.open(CompressedRandomAccessReader.java:44)
at org.apache.cassandra.io.sstable.SSTableReader.openDataReader(SSTableReader.java:949)
at org.apache.cassandra.io.sstable.SSTableScanner.<init>(SSTableScanner.java:72)
at org.apache.cassandra.io.sstable.SSTableReader.getScanner(SSTableReader.java:796)
at org.apache.cassandra.db.RowIteratorFactory.getIterator(RowIteratorFactory.java:88)
at org.apache.cassandra.db.ColumnFamilyStore.getRangeSlice(ColumnFamilyStore.java:1329)
at org.apache.cassandra.service.StorageProxy.getRangeSlice(StorageProxy.java:806)
at org.apache.cassandra.thrift.CassandraServer.get_range_slices(CassandraServer.java:697)
at org.apache.cassandra.thrift.Cassandra$Processor$get_range_slices.process(Cassandra.java:3202)
at org.apache.cassandra.thrift.Cassandra$Processor.process(Cassandra.java:2889)
at org.apache.cassandra.thrift.CustomTThreadPoolServer$WorkerProcess.run(CustomTThreadPoolServer.java:187)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:636)


I have made the below changes to Cassandra.bat and the problem got resolved.

























I have updated the two highlighted values from -Xms1G^, -Xmx1G^ to -Xms2G^, -Xmx2G^ by allocating 2GB of heap memory for Cassandra. 

How to connect to Cassandra server running in Amazon EC2 using Cassandra client in local environment?

Below steps need to be followed, if you want to connect to Cassandra instance running in Amazon EC2 using the Cassandra client running in local environment.

  1. Goto EC2 Management Console
  2. Click on Security Groups under Network and Security on the left menu
  3. Select your Security Group associated with your instance and click on Inbound Tab
  4. Find out what is the source for ALL Port (Service). If the source is sg-xxxxxxxx, then delete the same.
  5. Add a new rule by selecting the below options: Create a new rule: All Traffic Source: 0.0.0.0/0
  6. Add Rule and click on Apply Rule changes
  7. To verify if you are able to connect to Cassandra server, run the cassandra client from your local machine like below:
cassandra-cli -host ec2-XX-XXX-XX-XXX.us-west-2.compute.amazonaws.com -port 9160

How to release the Cassandra port 7199 used by other application?

After downloading the Cassandra database from Apache Cassandra website and when you try to execute the cassandra.bat under /bin folder, you may get the below error if the port 7199 is used by some other application:

Starting Cassandra Server Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: 7199; nested exception is: java.net.BindException: Address already in use: JVM_Bind. Can anyone assists me in running cassandra successfully.

How to identify which application is blocking port #7199 and how to kill that?


Open the TCPView application and sort the output by Port
Click on the record which points to Port - 7199
Right click and "End Process"
Now, run the Cassandra.bat and it should work.

Thursday, April 18, 2013

Creating first Android app using C# / Dot42

First, you have to download the Dot42 setup from https://www.dot42.com/download.aspx.  The community license is free for a single developer and free apps can be developed using the community license.  For commercial purpose, you have to purchase the professional license.

Install the Dot42Setup.exe and follow the steps to complete the installation:
























Now, open the Visual Studio 2010 and create a new project using Dot42 template.  Select dot42 Applicatino project and provide a application name.



Once you click on OK, you have to select the Target framework version along with the certificate.  While creating the application for the first time, you have to select the  icon and create a new certificate.












Once you click on Ok, the new project gets created with two files (MainActivity.cs and MainLayout.xml which is the layout xml file).






















By default, a TextView is created with the default Hello World as the text.  Now, let us add a new button and on click of the button, we can show an dialog.  First, we have to add the button in the Layout xml file.


  <Button
      android:id="@+id/button"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="Show Alert"/>

In the OnCreate method, we have to identify the button in the layout file first and add event handler to it.

        var button = FindViewById<Button>(R.Ids.button);

        button.Click += ShowOnClick;

Now, we have to create the method ShowOnClick and write logic to show the alert dialog.


            var builder = new AlertDialog.Builder(this);
            builder.SetMessage("Test alert dialog !");
            var dialog = builder.Create();
            dialog.Show();

Now, the MainActivity.cs file looks like below:














Okay, it's time now to debug and deploy the application into the mobile device.  I'm using HTC explorer mobile for deploying this test application.  Since HTC Explorer runs on Andorid 2.3 version, I'm changing the target version to 2.3 from Project -> Properties -> Android -> Android Version -> 2.1.

I have installed HTC Sync application in my local machine and connected my mobile using USB port / HTC Sync option.

Now, press F5 to deploy the application.  Once you press F5, the device connected to the USB port gets listed in the list.  I'm selecting the HTC mobile and clicking on Ok.




























The application is deployed into the mobile device successfully.

Clicking on the button on the application, generates the alert dialog like below.














That's it :) .... I have created my first Android app in less than 10 minutes.

Wednesday, April 17, 2013

Android application development using C#

I wanted to develop some apps for Android platform and primarily being a .net developer, I was thinking of switching to Java platform for developing Android applications.

Then, I thought of evaluating alternate options to develop Android apps using C# itself.  I came across the below options.

1. Dot42
    http://www.dot42.com/

2. Mono Project / Xamarin
    http://www.mono-project.com/Main_Page
    http://xamarin.com/

I started evaluating Dot42 and found as a cool option to build Android apps using Visual Studio 2010 itself.   Dot42 doesn't require any runtime environment (like Mono) and we can debug and deploy the application into Android devices from Visual Studio itself.

The API names are exactly same with the DLLs provided by Dot42.  If we know the method name in Java for any functionality, we can use method name (only casing is the difference) in C#.

I was able to create my first test application using C# in less than 10 minutes.  I will share in my next blog on how to create the test app using Dot42.

Tuesday, April 16, 2013

Iterating through a SQL Server script using C#

I hope you would have read my previous blog on how to parse the SQL Server script using C#.

Once the script is parsed successfully, the entire script is available in TSqlScript object.  A TSqlScript can contain multiple TSqlBatch objects.  Each TSqlBatch object contains multiple TSqlStatement objects to it.

For each of the DDL/DML statements, there is a class associated to it (say SelectStatement, DeleteStatement, UpdateStatement etc.,).  All these classes are inherited from the main abstract class TSqlStatement.