RPC example II -- finding prime numbers - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

RPC example II -- finding prime numbers

Description:

Client broadcasts a message to all machines declaring a new epoch. ... One way of recovery is by Voting, whereby a number of 'good servers' sign a transmitted message. ... – PowerPoint PPT presentation

Number of Views:243
Avg rating:3.0/5.0
Slides: 9
Provided by: kk184
Category:

less

Transcript and Presenter's Notes

Title: RPC example II -- finding prime numbers


1
RPC example II -- finding prime numbers
/ Return TRUE If n is prime / int isprime(int
n) int I for (I 2 II lt n I)
if ((n I) 0) return 0 return 1
  • / print a list of primes between 1 and 1000 /
  • main()
  • int I, how_many, primes1000
  • how_many find_primes(1, 1000, primes)
  • for (I 0 I lt how_many I)
  • printf(d is prime\n, primesI)
  • / Find all primes between min and max, return
    them in an array /
  • int find_primes(int min, int max, int array)
  • int I, count 0
  • for (I min I lt max I)
  • if (isprime(I)) arraycount I
  • return count

2
primes.x
  • const MAXPRIMES 1000
  • struct prime_request
  • int min
  • int max
  • struct prime_result
  • int arrayltMAXPRIMESgt
  • program PRIMEPROG
  • version PRIMEVERS
  • prime_result FIND_PRIMES(prime_request) 1
  • 1
  • 0x32345678

3
p_server.c
  • include ltrpc/rpc.hgt
  • include "primes.h"
  • prime_result find_primes_1(prime_request
    request)
  • static prime_result result
  • static int prime_arrayMAXPRIMES
  • int i, count 0
  • for (i request-gtmin i lt request-gtmax i)
  • if (isprime(i)) prime_arraycount i
  • result.array.array_len count
  • result.array.array_val prime_array
  • return(result)

int isprime(int n) int i for (i 2 ii lt
n i) if ((n i) 0) return 0
return 1
4
p_client.c
request.min atoi(argv2) request.max
atoi(argv3) result find_primes_1(request,
cl) if (result NULL) clnt_perror(cl,
argv1) exit(3) for (i 0 i lt
result-gtarray.array_len i) printf("d is
prime\n", result-gtarray.array_vali)
printf("count of primes found d\n",
result-gtarray.array_len) xdr_free(xdr_prime_res
ult, result) clnt_destroy(cl)
  • include ltrpc/rpc.hgt
  • include "primes.h"
  • main(int argc, char argv)
  • int i
  • CLIENT cl
  • prime_result result
  • prime_request request
  • if (argc ! 4)
  • printf("usage s host min max\n", argv0)
  • exit(1)
  • cl clnt_create(argv1, PRIMEPROG, PRIMEVERS,
    "tcp")
  • if (cl NULL)
  • clnt_pcreateerror(argv1)
  • exit(2)

5
RPC Semantics in the Presence of Failures
  • Five different classes of failures in RPC
    systems
  • Client Cannot Locate the Server
  • Server might be down or New server with old
    client
  • return -1 for error is not good enough because
    the return value might be -1 (e.g. adding 7 to
    -8)
  • raise an exception (like in Ada ! so write your
    own SIGNOSERVER)
  • Lost Request Messages
  • easiest to deal with , just have the kernel start
    a timer when sending the request, and resend it
    if time-out.
  • Lost Reply Messages
  • use timer again , but this time you cannot tell
    whether the reply is lost or the server is just
    slow
  • idempotent transactions
  • reading the first 1024 byte of a file is
    idempotent
  • transferring 1 million from a bank account is
    non-idempotent
  • solution 1 construct all requests in an
    idempotent way
  • solution 2 have the clients kernel assign each
    request a seq. number

6
RPC Semantics in the Presence of Failures (cond.)
  • Server Crashes
  • In the 2nd case, the system has to report failure
    back to the client
  • In the 3rd case, it can just retransmit the
    request
  • at least-once semantics
  • at most-once semantics
  • exactly once semantics

7
RPC Semantics in the Presence of Failures (cond..)
  • Client Crashes
  • unwanted computation is called orphan
  • solution 1 extermination -- keeping log for
    every request
  • solution 2 reincarnation -- divide time into
    sequentially numbered epochs. Client broadcasts a
    message to all machines declaring a new epoch.
    All remote computations are killed.
  • solution 3 gentle reincarnation -- same as 2,
    but remote computations are killed only if they
    cannot find their owner
  • solution 4 expiration -- each RPC is given a
    standard time T to do a job, if it cannot finish
    within T, it have to ask the for another quantum.
    After the client crash, it wait for T unit of
    time to make sure that all orphans are gone, then
    it reboots.
  • note none of these methods are desirable. Worst
    yet, killing an orphan may have unforeseen
    consequences. For example, suppose that an orphan
    has obtained locks on one or more files or
    database records. If the orphan is killed
    suddenly, these locks may remain forever. Also,
    an orphan may have already made entries in
    various remote queues to start up other processes
    at some future time, so even killing the orphan
    may not remove all traces of it.

8
Byzantine Failure
  • It represent the worst possible failure semantics
    in
  • of a server.
  • It models a situation in which most computers
    work correctly but fault computers work a
    maliciously as possible.
  • Faulty computers can send contradictory messages
    to different recipients or impersonate one
    another.
  • One way of recovery is by Voting, whereby a
    number of good servers sign a transmitted
    message.
Write a Comment
User Comments (0)
About PowerShow.com