יום רביעי, 16 באפריל 2014

Explicit resource locking in sqlserver

I had a problem where I need explicit locking of resources in the SQL SERVER.
When sp1 run I need to prevent sp2 to run in parallel.
The stored procedures handle deferent DataBase resources so the transaction locking can’t help in this case . 

I have found the following article that helped me solve the problem:

http://www.mssqltips.com/sqlservertip/3202/prevent-multiple-users-from-running-the-same-sql-server-stored-procedure-at-the-same-time/?utm_source=dailynewsletter&utm_medium=email&utm_content=headline&utm_campaign=20140414

The the solution is based on the  sp_getapplock command.

Exec @rc = sp_getapplock @Resource='myLock' -- the resource to be locked can be any mutex name

         , @LockMode='Exclusive'  -- Type of lock

         , @LockOwner='Transaction' -- Transaction or Session

         , @LockTimeout = 15000 -- timeout in milliseconds, 15 seconds

Committing or aborting the transaction release the lock.
allow voiding the call to sp_releaseapplock

Don’t forget to check if timeout error occurred after the sp_getapplock has returned.

I although learn from the article to use the :
set @msg= convert(varchar,getdate(), 114) + ' requesting lock'
raiserror (@msg, 0, 1) with nowait

in order to output debug strings while executing a test code.

יום שלישי, 15 באפריל 2014

JCLOUDS blob storage for openstack swift

We use Jclouds blob storage in order to manage the Blobs in our private cload swift blob storage .
The following code demonstrates creating , writing , exploring and reading from swift using jcloud SwiftBlobStore.

package com.gmuav.playwithjcloads;
import java.io.IOException;
import org.jclouds.ContextBuilder;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.StorageMetadata;
import com.google.common.base.Charsets;
import com.google.common.io.ByteSource;
public class PlayWithSwift {
  
   public static void main(String[] args) throws IOException {
 
    
      String identity = " --- ";
      String credential = " --- ";
      String containerName = "myContainer";
      
       ByteSource payload = ByteSource.wrap("This is the Data as text ".getBytes(Charsets.UTF_8));
     
      BlobStoreContext context = ContextBuilder.newBuilder("swift")
                                               .credentials(identity, credential)
                                               .buildView(BlobStoreContext.class);
      try {
         // Create Container
         BlobStore blobStore = context.getBlobStore();
         blobStore.createContainerInLocation(null, containerName);
         String theBlobName = "myFolder/myData";
    
         Blob blob = blobStore.blobBuilder(theBlobName)
            .payload(payload)
            .contentLength(payload.size())
            .build();
       
         blobStore.putBlob(containerName, blob);
           // List Container
         for (StorageMetadata nextBlob : blobStore.list()) {
            System.out.println("NextBlob:" + nextBlob.getName());
         }
         
         Blob theRetreivedBlob =  blobStore.getBlob(identity, theBlobName);
               
         String theRetValue = new String (((ByteSource)theRetreivedBlob.getPayload()).read() , Charsets.UTF_8);
         
          System.out.println("The blob data  " + theRetValue);
         
         
      } finally {
         context.close();       
      }
   }
}

Capture29
 


References:
jclouds-examples

Creating attributes in sysfs

The sysfs allow User space kernel space simple communication  .

The code

#include <linux/kobject.h>
#include <linux/string.h>
#include <linux/sysfs.h>
#include <linux/module.h>
#include <linux/init.h>
/*
 * The module demonstrats creating 2 attributes in a subdirectory of sysfs.
 *  ls the /sys/kernel/mykobject  
 */
static int intValue = 0;
static char  TxtBuffer[50];
static ssize_t attr_show(struct kobject *kobj, struct kobj_attribute *attr,
        char *buf)
{
 if (strcmp(attr->attr.name, "TxtBuffer") == 0)
 {
  return sprintf(buf, "%s\n", TxtBuffer);
 }
 
 if (strcmp(attr->attr.name, "intValue") == 0)
 {
  return sprintf(buf, "%d\n", intValue);
 }
 
 return 0;
}
static ssize_t attr_store(struct kobject *kobj, struct kobj_attribute *attr,
         const char *buf, size_t count)
{
 
 if (strcmp(attr->attr.name, "TxtBuffer") == 0)
 {
  strcpy (TxtBuffer, buf);
  return count;
 }
 
 if (strcmp(attr->attr.name, "intValue") == 0)
 {
  int theTmpVar;
  sscanf(buf, "%du", &theTmpVar);
  intValue = theTmpVar;
  return count;
 }
 return 0;
}
static struct kobj_attribute intValue_attribute =
 __ATTR(intValue, 0666, attr_show, attr_store);
 
static struct kobj_attribute TxtBuffer_attribute =
 __ATTR(TxtBuffer, 0666, attr_show, attr_store);
 
static struct attribute *attrs[] = {
 &intValue_attribute.attr,
 &TxtBuffer_attribute.attr,
 NULL, 
};
static struct attribute_group attr_group = {
 .attrs = attrs,
  .name = NULL,   /* we want them in the same directory */
};
static struct kobject *mykobject;
static int mykobject_init(void)
{
 int retval;
 mykobject = kobject_create_and_add("mykobject", kernel_kobj);
 if (!mykobject)
  return -ENOMEM;
 
 retval = sysfs_create_group(mykobject, &attr_group);
 if (retval)
  kobject_put(mykobject);
 return retval;
}
static void mykobject_exit(void)
{
 kobject_put(mykobject);
}
module_init(mykobject_init);
module_exit(mykobject_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Zvika Peer  <zvikapeer@hotmail.com>");

After installing the module using insmod let test it. The module directory is :
ls  /sys/kernel/


Inspecting  the mykobject attributes
zvika@zvika-Linux:~/Learn/Drivers/HelloWorld$ ls  /sys/kernel/mykobject
intValue  TxtBuffer

Inserting Data into the attributes:


zvika@zvika-Linux:~/Learn/Drivers/HelloWorld$ sudo echo "Hello zvika" > /sys/kernel/mykobject/TxtBuffer
zvika@zvika-Linux:~/Learn/Drivers/HelloWorld$ sudo echo 164  > /sys/kernel/mykobject/intValue


Retrieving the data back from the attributes:

zvika@zvika-Linux:~/Learn/Drivers/HelloWorld$ sudo cat  /sys/kernel/mykobject/intValue
164
zvika@zvika-Linux:~/Learn/Drivers/HelloWorld$ sudo cat  /sys/kernel/mykobject/TxtBuffer
Hello zvika

python __get__ magic method

I used the __get__ python magic method in order to implement  explicit conversion of class :
The following example converts a string wrapper class into the string length:

class TheConverter:
    def __init__ (self):
        pass
    def __get__ (self, instance, owner):       
        return len ( instance.mValue)
   
class ToGetConverted:
    def __init__ (self ,pValue ):
        self.mValue = pValue
    LenConvertor = TheConverter()
print (ToGetConverted("Hands Up").LenConvertor)
if __name__ == '__main__':
    pass

The sample returns : 8

References:
magic words


 


יום שישי, 7 במרץ 2014

Open stack cinder block

I have found the following blog post regarding Open Stack cinder block:
laying-cinder-block-volumes-in-openstack-part-1-the-basics
Cinder allows to attach external  storage volume into the cloud in addition to the instance ephemeral storage

The cinder api can be found here :
cinder api
Allows to create volumes , update volumes , delete volumes , list volume information
Handle snapshots

Map interface design review

Last week I had design review session about Map wrapper interfaces.
The interface is part of a module that allows a programmer to switch map infrastructure implementations within its product transparently  to the logic of the UI layer 

Part of the proposed interface looks something like this :
Capture28
The goal of the MapSurface interface is to allow adding drawing annotations on the map like routes , spots areas etc.

Prons

1.KISS:
Very simple interface allow the programmer quickly learned how to use it even without documentation and code samples . 


Cons

1.Open close principle violation:
In order to add handling for new widget type for an example a closed curved etc the IMapInterface  should be changed .

2.The interface does not allow me to use the created route in a surface of a map in other window .


 

 

 

יום שבת, 19 באוקטובר 2013

Configure netbeans for Php debugging

In order to allow Php debugging on NetBeans IDE 7.4 I did the following steps :

1.Change the php ini file as follow :
[XDebug]
zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
xdebug.profiler_append = 0
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir = "C:\xampp\tmp"
xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "127.0.0.1"
xdebug.trace_output_dir = "C:\xampp\tmp"

The php ini file is located under :
C:\xampp\php\php.ini

2.Make sure that the tools – options  in the netbeans is like this
Capture1

The project properties :
Capture2
Restart the xamp apache server .

and walla

Capture3