64 Prerna Jain Dspractassg11
64 Prerna Jain Dspractassg11
- 11
THEORY:
Distributed File Systems:
Definition: A distributed implementation of the time-sharing model of a file system
wherein multiple users share files and storage resources.
▪ naming
▪ transparency (works hand-in-hand with naming)
▪ concurrency (including synchronization)
▪ replication (caching, with consistency checks)
▪ platform independence (heterogeneity)
▪ fault tolerance
▪ consistency
▪ security
▪ efficiency
1)Naming
2)Definition: location transparency - a file's name does not reveal the file's physical
storage location. A file name still denotes a specific, although hidden, set of physical
disk blocks.
3)Definition: location independence - a file name does not need to be changed when
the file's physical storage location changes.
Naming Schemes:
1. Files are named by a combination of their host name and local name;
guarantees a unique systemwide name.
2. Attach remote directories to local directories, giving the appearance of a
coherent directory tree; only previously mounted remote directories can be
accessed transparently
3. Total integration of the component file systems.
- A single global name structure spans all the files in the system.
- If a server is unavailable, some arbitrary set of directories on different
machines also becomes unavailable.
Architecture:
A DFS typically is built from an architecture with components similar to the
following:
To reduce network traffic, remote access retains recently accessed disk blocks in a
cache, so that repeated accesses to the same information can be handled locally.
- If needed data not already cached, a copy of data is brought from the server to
the user.
- Accesses are performed on the cached copy.
- Files identified with one master copy residing at the server machine, but
copies of (parts of) the file are scattered in different caches.
- Cache-consistency problem - keeping the cached copies consistent with the
master file.
Location - Disk Caches vs. Main Memory Cache
- More reliable.
- Cached data kept on disk are still there during recovery and don't need to be
fetched again.
▪ Write-through - write data through to disk as soon as they are placed on any
cache. Reliable, but poor performance.
▪ Delayed-write - modifications written to the cache and then written through to
the server later. Write accesses complete quickly; some data may be
overwritten before they are written back, and so need never be written at all.
4) Consistency:
Cache consistency is a concern for all types of caching scenarios. This includes
processor cache, application cache (e.g., browsers), and distributed data caches.
the locally cached copy of the data consistent with the master copy? ▪
▪ Is
Client-initiated approach
- Server records, for each client, the (parts of) files it caches.
- When server detects a potential inconsistency, it reacts.
5) File Replication:
import java.net.*;
import java.io.*;
import java.sql.*;
class Trainserver
{
public static void main(String args[])
{
String Query;
ResultSet rs = n ull;
String msg;
int pnr = 0,trainnum= 0;
String from = new String();
String to = new String();
String date = new String();
String name = new String();
try
{
ServerSocket ser=new ServerSocket(8000);
System.out. println("Server Started...");
Socket soc=null;
soc=ser.accept();
System.out. println("Received Connection: "+soc.getInetAddress().getHostAddress());
DataOutputStream out=new DataOutputStream(soc.getOutputStream()); BufferedReader
in = new BufferedReader(new
InputStreamReader(soc.getInputStream()));
try{
Class.forName(" oracle.jdbc.driver.OracleDriver");
Connection
conn=DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:XE","hr","hr");
Statement stmt=conn.createStatement();
msg = in.readLine();
pnr = Integer.parseInt(msg);
Query = "Select * from train where pnrno = "+pnr;
rs = stmt.executeQuery(Query);
if(rs.next())
{
pnr = Integer.parseInt(rs.getString(1));
from = r s.getString(2);
to = rs.getString(3);
date = r s.getString(4);
name = r s.getString(5);
trainnum=Integer.parseInt( r
s.getString(6));
}
else
{
System.out.println("");
}
}
catch(SQLException e)
{
System.out.println("Error Caught: "+e);
}
out.writeBytes("".v alueOf( p nr))
;
out.write(10);
out.writeBytes(from);
out.write(10);
out.writeBytes(to);
out.write(10);
out.writeBytes(date);
out.write(10);
out.writeBytes(name);
out.write(10);
out.writeBytes("".v alueOf( t rainnum));
out.write(10);
soc.close();
}
catch(Exception e)
{
System.out.println("Error Caught: "+e);
}
}
}
ava.io.*;
import j
import j ava.net.*;
class Traindbclient
{
public static void main(String args[])
{
Socket objclient= null;
BufferedReader br = null,in = null;
DataOutputStream out = n ull;
int pnr = 0;
try
{
objclient = new Socket("Localhost",8000);
in = new BufferedReader(new InputStreamReader(objclient.getInputStream()));
br = new BufferedReader(new
InputStreamReader(System.in));
out = new DataOutputStream(objclient.getOutputStream());
System.out.println("Enter the PNR NO: ");
pnr = Integer.parseInt( br.readLine());
out.flush();
out.writeBytes("".v alueOf( p
nr))
;
out.write(10);
System.out.println("PNRNo:"+in.readLine());
System.out.println("SOURCE :"+i n.readLine());
System.out.println("DESTINATION: "+in.readLine());
System.out.println("JOURNEY DATE: "+in.readLine());
System.out.println("CUSTOMER NAME:"+in.readLine());
System.out.println("TRAIN NO: "+in.readLine());
objclient.close();
}
catch(Exception e)
{
System.out.println("Error Caught: "+e);
}
}
}