Fine. Now,
let's see the various states of a transaction.
OK see let us assume that we are taking a single transaction single transaction.
And as you know we can, we will have a set of operations on this transaction.
Right.
Let us assume it is something like, read of A, A equal to A minus hundred.
Then we have something like write of A.
Then we have something called as read of B. B equal to B plus hundreds and a write of B which means
I am transferring 50 dollars from A's account to B's account, right?
Fine.
And we have something called as Commit.
Ok. We have something called called as Commit.
Now what do we mean by this is, at the end of our transaction we generally do something.
called as Commit.
Which means we are going to say that whatever changes this transaction has made so far has been made
as permanent inside the hard disk.
Right?
See what has happened here.
We are, we are having a CPU fine.
We are having registers it fine, and we are having RAM which is not important here.
And also we're going to have something called as Hard Disk right? Now you because of the read of A
We are moving the data from hard disk to register, fine? And using this we are going to update the value fine? And we're
going to write this value inside the hard disk, right?
So we have written the updated value of A inside the hard disk also we're going to do the same
for B right? We're going to update the value of B in the hard disk, fine? Now though we have written both these
values both the updated values inside the hard disk, these values are not permanent until we do something
called as Commit, okay? Until we do something called as Commit which means though I am Writing these values inside
inside the hard disk this is not permanent they are just temporary .OK? So what we do in general is at the
end of the transaction we will do something called us commit which means we're going to say that whatever
changes this transaction has made or whatever the effect this transaction has made that will be
made as permanent, ok? That we do by using something called as commit, ok? This is a command. Fine.
So now let's see what are the various stages of a particular transaction.
Okay.
First thing is the transaction will be in active state, Ok? It will be in active state let us assume
that the transaction is, either, let us assume we have just now started the transaction okay? Which means
we are over here, now the transaction is definitely in active state, OK?
Now whether we are, whether we are, in this time or this time or this time or this time or this time
so in whatever time period we are in, we can say that the transaction is in active stage. Right?
Active state at this point of time the transaction is in Active state now let us assume, that all the steps of
a particular transaction are over except, commit is not over.
Ok?
We have not committed a transaction see at this point of time all the operations of a particular
transaction are over, but we didn't do something called as commit. Okay.
Then we say that the transaction is partially complete, ok? The transaction is partially complete.
So from active state we can go to something called us partially complete state.
Ok? We can definitely do that we can go from active state to partially complete state, how? In case if we
have done all the operations except commit. Ok, except commit fine. Now, from active state obviously our transaction
can even fail. Right? Obviously it is possible our transaction can definitely, let us assume that transaction
has failed over here. Ok it has failed over here in that case what we will do we will perform something
called this rollback, what do you mean by rollback.
We are going to undo the effects of this partially complete transaction.
Okay.
See because of the partially complete transaction what has happened A's value has been subtracted by hundreds.
But we have not added hundred to B's value.
That's what we have done till this point.
No these are partial effects of this transaction.
Why.
Because the transaction is not yet complete.
So what we will do.
We will definitely perform the rollback.
Which is as same as just aborting the transaction.
Right?
Which is our same as aborting the transaction.
So our transaction can get failed anywhere over
Here even our transaction can get failed over here, okay can definitely happen.
Even if our transaction fails at this point of time which means whatever effect this transaction
has made.
They are just partial effects and so they has to be undone right? Which means..
See let us assume the balance of A is thousand dollars fine? The balance of B was 900 dollars initially
right initially.
Now let us assume that we have completed the all the operations till this point but, we have not performed the
commit, right?
In the case what will happen A's value should have become 900 fine? And B's value should have become
thousand, right? It should have become thousand fine.
Now, we didn't commit the transaction.
Let us assume, this transaction got failed at this point of time.
Right, at this point of time. So, whatever changes we have made in the hard disk at this point of time they
are not permanent. Right?
They are just temporary because we have not done commit.
So, they are just partial effects. So, these partial effects will be undone.
How can we do that?
Just restore to the previous value, when you when you did when you started the transaction right.
In that case this will become thousand and this will become 900 right.
This is what we mean by rollback. Right? Now,
why did we do this rollback?
Because, we have aborted the transaction. Right, we have aborted the transaction.
If you want you can even write abort and rollback. If you want you can write this step.
These are just names which we have created.
Ok, fine.
So, from active state a transaction go to either partially complete state which means from this state,
it can either go to this state or it can even fail in between. Right? It can fail in between, fine and from
partially complete state from this state,
our transaction can either go to commit. In case, let us assume the transaction didn't fail and we have
executed this command. In that case our transaction can go from partially complete state to committed
state. Right? Where as in case if our transaction fails at this point of time,
it is definitely possible, in that case it can go to failed state, right, failed state. Now, from partially
complete step I can go to failed state as well as from active state I can go to failed state.
I think you understood the point.
Why?
Because our transaction can get failed at this point, at this point, at this point or even it can get failed
at this point.
Okay, so from both these scenarios we can both to failed state, fine, from failed state obviously,
there is no other way, we need to abort the transaction, right.
If you want to go write abort and rollback. Ok? If you want you can write it.
So, whatever it is, in case a transaction fails we need to definitely abort it and we need
to rollback.
Fine.
Now, from partially complete state our transaction can go to committed state. Right?
It is definitely possible.
So, these are the various states of a transaction.
Ok, various states of a transaction.
Let us assume that we have performed all the operations except commit.
Then we say that the transaction is in partially complete state right.
Now let us assume, we didn't
perform commit,
also we have not done all the operations.
Let us assume we didn't
perform this single operation we, our transaction is at this point of time.
Ok, then we can say that the transaction is definitely in active state.
Ok.
Whereas in case if a transaction has performed all the operations except commit.
Then we say it as part, the transaction is in partially complete state. Right? Whereas is in case if a transaction
has failed in between,
then we say that the transaction is in failed state. Then in that case,
we need to definitely abort the transaction. Right?
Whereas in case if we, our transaction has even executed this
come commit command,
then we say that the transaction is in committed state. Ok or
we can say that the transaction is complete.
Okay.
So from partially complete state, we can go either committed state or we can go to failed state.
Fine.
See practically,
we generally use commit at the end of a single transaction. Okay?
The end of a transaction to make the, to make the changes in hard disk as permanent.
Okay, that's why we use this commit statement.
But theoretically, we can even use commit in between a transaction.
Okay theoretically it is possible.
So, let us assume that we have performed some operations and I have used commit, fine?
And let us assume I'm still doing some other operations something like read of A, write of A
or some ALU operation or something like this.
Ok? I am doing some operations and at the end I am having commit as usual. Right? I am having commit
as usual.
Now let us assume that this transaction got failed somewhere over here, ok, anywhere over here. Now,
let us assume that this transaction got failed somewhere over here. Right?
In that case what will I do?
I will definitely perform rollback, right.
I will definitely perform rollback. Now, what will happen because of this rollback.
See this point, because of this rollback.
I will be heading to this position not this position.
Why?
Because whatever changes I have made till this point, till this point, has been made as permanent because
of this commit statement.
Right.
Because of this comment statement.
Now these changes cannot be undone.
Why?
Because we have made them as permanent because of this commit command.
Right? Now in case if a transaction fails in between over here, either here or here or here or somewhere then,
we will obviously perform rollback because this transaction got failed but because of that rollback, what
we will be heading to this position, which means whatever changes we have made till this point has
been made as permanent only the effects of these statements will only be the effects of these statements
will be undone.
Okay I think you're getting the point.
Whatever changes we have made till this point has been made permanent because of this commit.
Now in case if a transaction fails in between then we will be performing rollback and because of that
roll back, only these effects will be undone.
These effects cannot be undone because they have been already made as permanent because of this commit
statement. Right?
Fine.
Now again, even let us assume this transaction has again performed commit, right, again performed commit.
Now, in case if you are performing read of A, write of A
and in case if a transaction got failed over
here, we will obviously perform rollback.
In that case, only these effects will be undone. Ok, which means so we whatever changes we have made
till the point will be made as permanent.
Because of this commit.
Okay I think you're getting the point.
This commit is actually used to say that ok, whatever I have till this point has to be made as
permanent irrespective of whether the transaction fails hereafter or not.
Okay fine.