Posts

Showing posts from March, 2012

hardware raid vs software raid

A raid is considered hardware based when it is implemented in hardware. In software raid it just uses software instead of hardware. There are many difference between hardware and software raid. Describe below hardware raid vs software raid: 1. Cost : To implement hardware raid we need hardware disk but in software raid we just use software. So we can say that hardware raid costly than software raid. 2. Complexity : Software raid is a part of OS and it works on partition level. Sometimes software raid increases complexity but the complexity level of a hardware raid is low. 3. Performance : The performance of hardware raid always high but in software raid it depends upon use of the software. 4. Throughput :  Hardware Raid offers higher throughput but software raid do not offers higher throughput. 5. Faster rebuilds :  If any system failure occurs hardware raid recover it easily but it is not easy to rebuild software raid system. To improve this content plz make your comment.

Different raid level in database

Image
The word RAID means Redundant Arrays of Independent/Inexpensive Disks. In many web application, database application we need to store big data. To store this data we need many hardware disk. Large number of disks helps you to read or write data item in very short time. There are many kinds of RAID or hardware disks. Each disks has special characteristics. Some disks reliable but not good in performance. Here I explain different raid levels in database : RAID level 0 : Raid level 0 is non redundant disk array. That means in the disk of raid 0 has no extra/redundant information. Raid 0 offers best performance because it never needs to update redundant data. In raid 0 if either disk fails, all data is lost. The data is divided into block and distributed across drives in array. Two disk used most often, half data on each disk. Non redundant disk arrays are widely used in super computing environment. To understand raid level 0 see this image below: Raid level 1 : Raid level 1 is called mir

Solving Potentially dangerous Request.Form with custom attribute in MVC3

Image
If you punch in “<” character while filling a MVC web form (or even ASP.NET) and press submit, you’ll encounter a System.Web.HttpRequestValidationException exception. I.e., results in: Upon search, you’ll find few common options to resolve this. I've tried to consolidate them and also have added an interesting approach at end which I find very useful for handling this issue: Option-1: Disabling RequestValidation through Web.Config Adding following tag in Web.Config: Pros : Easiest to do!! Cons : Skips validation throughout application. As a good rule, Validation should be explicitly bypassed but by setting this option, we are implicitly bypassing validation which is not good. Option-2: ValidateInput attribute Another option that resolves this problem is using ValidationInput = false attribute on Controller. For example: [ValidateInput(false)] [HttpPost] public ActionResult Index(MyViewModel vModel) { return View(); } Pros: Easy to use and can be applied only on s

Implementation of Locking in database

Image
A lock manager used to maintain lock request and lock response. The lock manager reply message when lock grant or not grant. Lock manager reply two kind of message such as a transaction locked message and  unlocked message. The lock manager maintains a data structure called a lock table to record granted locks and pending requests. In this data structure the data item maintains a linked list of records. Each record of the linked list for a data item notes which transaction made the request, what lock mode it requested. The lock table uses hash table indexed on the name of the data item being locked. This picture shows an example of a lock table. This table contains locks for five different data items 14, 17, 123, 144, and 1912. Black rectangles indicate granted locks, white ones indicate waiting requests. The lock manager processes requests in two way first one is lock request and second one is unlock request: 1. Lock request: When first lock request message arrives, the lock manager

Two-Phase Locking Protocol

Image
To maintain serializability we use two-phase locking protocol in database transaction . Specially we use the following two protocol for data locking purpose. We divide locking protocol into two phase. First phase acquire locks and second phase release the locks. Given below the two-phase locking protocol. 1. Growing phase: A transaction firstly acquired locks, but may not release any lock.   2. Shrinking phase:   A transaction may release locks, but at the time not taking any new locks. Initially, in the growing phase a transaction acquires locks as needed. Once the transaction start to release locks, it enters the shrinking phase. Now consider this transaction lock-S(A); read(A); lock-S(B); read(B); display(A+B); unlock(A); unlock(B); In the above transaction at first it acquire locks serially and then it releases the locks. This transaction follow two phase locking protocol.Two-Phase locking protocol ensures conflict serializability . But unfortunately locking can lead to an undesir

Replacing OuterHTML with AJAXHelper.ActionLink

There are various wayswhich provides unobtrusive way of updating UI with response from server via AJAX. One such option provided by MVC framework is Ajax.ActionLink. For example, @Ajax.ActionLink ( "TextOfLink", "ActionName", "ControllerName", new AjaxOptions() { UpdateTargetId = "DivToBeReplaced"} ) Above code generates a link which when clicked, calls an action called “ActionName” of the controller “ControllerName” and what ever is returned from this action, is displayed in a div with id “DivToBeReplaced”. That’s so easy!But there is a minor caveat in using UpdateTargetID . By default, it replaces the contents of div and not the div itself. Which means in following Razor code, <div id="mydiv"> Some Text @Ajax.ActionLink( "Refresh", "Index", new AjaxOptions(){UpdateTargetId = "myDiv"} <div> Clicking on generated action link would r

Understand database lock concept

Image
Database lock concept use when many user want to concurrently access in the database such as oracle database. When many user want to write the same data at a time, the data must be destroyed. To handle this problem we use locks. The data can be locked in two modes 1. Shared(S) mode: The data item can only be read. S lock is requested using lock-S instruction. 2. Exclusive(X) mode: The data item can be both read as well as written. X-lock is requested using lock-X instruction. The concurrency control manager handle the lock request. If you want to lock any data item, at first you need to make a request to the concurrency control manager. The concurrency control manager check it and give you the response is the transaction grant or not. When you lock a data item in share mode, another share mode can be able to lock it but when you lock it in Exclusive mode, another mode cannot lock the data at this time. To handle this compatibility database control manager use lock-compatibility matrix

View serializability in database

Image
Consider two schedule S1 and S2. The schedule S1 and S2 are said to be view equivalent if they met the  following  three conditions. Such that the data item is A: Condition 1: If in schedule S1, transaction T1 reads the initial value of A, then in schedule S2 also transaction T2 must read the initial value of A. Condition 2: If in schedule S1 transaction T1 executes read(A), and that value was produced by transaction T2, then in schedule S2 also transaction T2 must read the value of A that was produced by the same write(A) operation of transaction T2. Condition 3: The transaction that performs the final write(A) operation in schedule S1 must also perform the final write(A) operation in schedule S2.  In schedule S1 transaction T1 read(A) and also in schedule S2 transaction T1 read(A). In two schedule they read the same initial value of A. So this two schedule fulfill the first condition of view serializability. In schedule S1, T1 read(A) and produce value of A using write(A) operation a

Testing for conflict serializability

Image
A schedule is serializable or not, we need to test it. Now I show you how to easily determine conflict serializability of any schedule. To do this at first we need to clear understand about precedence graph. We know a graph consists of a pair G=(V,E), where V is a set of vertices and E is a set of edges. In this precedence  graph V= V means vertices, all transaction in a schedule consider as a vertices such that T1 and T2 is two vertices for a schedule S. E= E is edge, an edge consists T1 to T2 if the schedule fulfill the three condition :               1. T1 executes write (A) before T2 executes read (A)               2. T1 executes read (A) before T2 executes write (A)               3. T1 executes write (A) before T2 executes write (A) Now consider the following picture. In that picture we see there are three schedule S1, S2 and S3. At first we sketch precedence graph for S1. S1 has two vertices T1 and T2 and also has one edge  T1 to T2 because all the instructions of T1 are executed

What is Disk mirroring, Bit level stripping and block level stripping

Image
Disk mirroring or shadowing: Disk mirroring or shadowing is the process whereby each disk has a shadow or mirror disk. In the shadow or mirror disks data is written to simultaneously. Disk mirroring used to backup purposes and it is costly. In disk mirroring the data is duplicated on 2nd disk. If one disk fails or destroyed we can recover the original data from  2nd disk. Given below the picture of disk mirroring. Bit level Stripping: With multiple disk, we can improve transfer rate by striping data across multiple disk. When we split data bits across multiple disk, we call it bit level striping. Block level stripping:  When we split data bits across multiple disk, we call it block level striping.

Conflict Serializability in database

Image
To maintains database state consistency we introduce serializability. Using serializability we can understand which schedule will ensure consistency, and which schedule will not. When we are capable of converting a concurrent schedule into a serial schedule then we cal it serializable schedule. A schedule is serializable if it is equivalent to a serial schedule. We divided this concepts into two parts 1. Conflict serializability  & 2. View serializability In this discussion I just clarify you the conflict serializability. Consider two instruction read, write and the data item A and B. When two instruction execute different data item such as read(A) and read(B), then we can swap the instruction without affecting the result of the schedule. But when the data item is equivalent to one another we need to consider following four condition.    a.   read (A ),    read ( A ).   they   don’t conflict.    b.   read ( Q),    write ( Q ).  They conflict.    c.   write ( Q),   read ( Q ).   The

Understand the Super key, primary key, Candidate key and Foreign key

Primary key: Primary key is one of the attribute of a relation that uniquely identifies a row on a touple. Super key: Super key is a combination of attributes of a relation that uniquely identify a database table. Candidate key or alternate key: Candidate key is a subset of super key. A candidate key is a single field on the least or minimum combination of fields that uniquely identifies each record in the table. Foreign key: A relation schema may have an attribute that correspond to the primary key of another relation. The attribute is called foreign key. Example: To clearly understand the database key I discuss it with example. See the example below Student student_id first_name last_name course_id A1 Kabir Rock L1 A2 Rahim Doc L2 A3 John Bon L3 A4 Bela Din L4 Consider the relation student. In that relation we uniquely identify the student using student_id, so it is primary k

Understand concurrent scheduling in database

To maintain database consistency we schedule the transaction.  Consistency is one of the main properties of database transaction . The main goal of concurrent scheduling is to allow multiple users can access the database without interfering each other. Consider the transaction T1 and T2 that wants to transfer funds from one account to another. T1 transfers $100 from account A to account B. It is defined as T1: read(A); A:=A-100; write(A); read(B); B:B+100; write(B). And transaction T2 transfer 10 percent of the balance from account A to account B. It is defined as T2: read(A); temp:=A*0.1; A: A-temp; write(A); read(B); B:=B+temp; write(B); Suppose the current values of account A and B are $1000 and $2000, respectively. When the transaction execute sequentially we call it serial schedule. Serial schedule is not concurrent schedule. We call it just schedule. If two transactions are running concurrently, the operating system may execute one transaction for a little while then perform a co

Importance of Concurrent scheduling in database

To reduce transaction waiting time and improve throughput we use concurrent scheduling in database. Concurrent means two or more transaction run at a time concurrently. There are two reasons for allowing concurrent scheduling. (a) Improved throughput and resource utilization:  We can divide a transaction into many subprogram. Some program related to I/O activity and some are related to CPU activity. When a transaction runs without concurrency, it takes full time to execute and at that time other transaction need to wait to run. But when a transaction run concurrently, some program run in the processor and some run in disks. So the waiting time of other program also decrease and the throughput also increase. Correspondingly the processor and disk utilization also increase. So we can say that concurrent execution improved throughput and resource utilization. (b) Reduced waiting time: Concurrent execution reduces the unpredictable delays in running transaction. In the database system ther