Assignment III
Assignment III
)
Jain Institute of Technology, Davangere
(A Unit of Jain Group of Institutions, Bengaluru)
# 323, Near Veereshwara Punyashrama, Avaragere, Davangere- 577003.
Solution :
1. List the female employees from Department number 20
earning more than 50000.
SELECT Fname, Lname
FROM EMP
WHERE gender = 'F' AND DNO = 20 AND salary >
50000;
2. Partially Committed –
After completion of all the read and write operation the
changes are made in main memory or local buffer. If the
changes are made permanent on the DataBase then the
state will change to “committed state” and in case of
failure it will go to the “failed state”.
3. Failed State –
When any instruction of the transaction fails, it goes to the
“failed state” or if failure occurs in making a permanent
change of data on Data Base.
4. Aborted State –
After having any type of failure the transaction goes from
“failed state” to “aborted state” and since in previous
states, the changes are only made to local buffer or main
memory and hence these changes are deleted or rolled-
back.
5. Committed State –
It is the state when the changes are made permanent on
the Data Base and the transaction is complete and
therefore terminated in the “terminated state”.
6. Terminated State –
If there isn’t any roll-back or the transaction comes from
the “committed state”, then the system is consistent and
ready for new transaction and the old transaction is
terminated.
Example
• Consider a table
2 UK 102 Testing UK
EMP_I EMP_COUNTR
D Y
1 INDIA
2 UK
DEPT table
101 Testing UK
102 Productio UK
n
EMP_DEPT_MAPPING table
Emp_i Dno
d
1 100
1 101
2 102
2 103
8a) CAP Theorem
MongoDB is a popular NoSQL database, follows to
the CAP theorem by prioritizing availability and partition
tolerance over strong consistency. It defaults to eventual
consistency but offers tools like replica sets and transactions
for stronger consistency when needed and making it
versatile for distributed environments. In this article, We will
learn about the Where Does MongoDB Stand in the CAP
Theorem in detail.
What is the CAP Theorem?
The CAP theorem was formulated by computer scientist Eric
Brewer in the early 2000s. It is a fundamental principle in
distributed systems. It states that in a distributed data store,
you can only achieve two out of three
guarantees: consistency, availability, and partition
tolerance.
Consistency: Every read receives the most recent write
or an error.
Availability: Every request receives a response, without
guaranteeing that it contains the most recent write.
Partition Tolerance: The system continues to operate
despite network partitions that may cause messages to be
delayed or lost.
Understanding these trade-offs is crucial when designing
distributed systems and selecting the
appropriate database technology.
How Distributed Systems Break Availability or Consistency?
In distributed systems, achieving both high availability and
strong consistency simultaneously can be challenging due to
the inherent trade-offs defined by the CAP theorem. Here’s
how:
Availability Breakdown: Distributed systems may face
availability issues when network partitions occur, leading
to nodes being unreachable. If a system prioritizes
consistency over availability, it may reject requests during
partitioning to maintain data integrity, thus reducing
availability.
Consistency Breakdown: Ensuring strong
consistency across distributed nodes requires
coordination, which can introduce latency and increase
the risk of failures if nodes cannot communicate
effectively. In scenarios prioritizing availability, the system
might sacrifice consistency to remain operational during
partitions, potentially leading to eventual consistency
models.
6. Load Balancing
Query Routing: MongoDB uses a query router (mongos) to
route queries to the appropriate shards, balancing the
load across the cluster.
Chunk Migration: To maintain balanced data distribution,
MongoDB can move data chunks between shards as
needed.
7. Geographically Distributed Clusters
Global Clusters: MongoDB supports geographically
distributed clusters, allowing data to be stored closer to
users for reduced latency and compliance with data
residency requirements.
Multi-Region Replication: Data can be replicated across
different regions, ensuring global availability and disaster
recovery.
8. Consistency and Durability
Write Concerns: MongoDB allows configuring write
concerns to specify the level of acknowledgment required
from the database for write operations, balancing between
performance and data durability.
Journaling: MongoDB uses journaling to provide durability
by recording write operations before they are applied to
the database.
9. Operational Simplicity
Automation: MongoDB provides tools for automation of
complex tasks such as provisioning, scaling, and backups.
Monitoring and Management: Tools like MongoDB Atlas
offer integrated monitoring and management capabilities
for distributed clusters.