Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Describe the server-side state obligation for each of all-or-nothing, at-mostonce, and at-least-once semantics. [3 marks] (ii) Describe the classes of distributed filesystem RPCs in which

Describe the server-side state obligation for each of all-or-nothing, at-mostonce, and at-least-once semantics. [3 marks] (ii) Describe the classes of distributed filesystem RPCs in which it is safe to use at-least-once instead of all-or-nothing semantics. [2 marks] (iii) A distributed filesystem stores object replicas on multiple servers for fault tolerance. Successful reads must be made to at least Qr servers, and writes must be made to at least Qw servers. The client submits requests to all servers simultaneously using a "MultiRPC". Describe when MultiRPC must resend (a) reads and (b) writes due to packet loss. [2 marks] (c) Java is a garbage-collected language: when an object is unreachable, it will be freed. Cycles can exist in which otherwise disconnected objects reference one another, preventing reference counts from reaching zero. Cycle detection addresses this problem: execution is suspended and the object-reference graph is searched for memory that can be recovered. Distributed garbage collection faces many of the same challenges: cycles may exist between objects on different servers, which cannot be detected by local garbage collectors in individual JVMs. (i) Ho2 marks] (ii) A developer implements a distributed garbage collector (GC) for RMI. The GC queries all nodes for graphs of local and remote references, identifying disconnected cycles spanning multiple JVMs. JVMs are notified of remote references that can be safely released to break cycles. Unfortunately, this does not work: when the system is busy, live references get broken, causing user-visible failures. Describe a scenario in which this algorithm, without additional synchronisation, may lead to incorrectness.

answer all questions

PUBLIC CLASS BALLOT which create ballot for the function

public class Ballot {

public int id; // unique identifier of voting card

public String candidate;

public Ballot next;

public Timestamp timestamp;

public boolean filled;

/**

*

* @param id

* represents the official identity number of the Ballot

* @param next

public Ballot(int id, Ballot next) {

// Provided - not to be changed

candidate = null;

this.id = id;

this.next = next;

this.filled = false;

this.timestamp = null;

}

/**

* Voting: the voting card is filled

*

* @param name of (possibly incorrect) candidate name

* @param time stamp of the vote

*

* need to fill the ballot: the vote

* need to check whether has been already filled (used for voting)

* and both name and time stamp are not null

*

* @return - true if ballot was successfully filled, false otherwise

*/

public boolean fill(String name, Timestamp time) {

if (this.candidate == name || this.timestamp == time ||this.filled == true) {

return false;

}

if(name != null && time != null) {

this.candidate = name;

this.timestamp = time;

this.filled = true;

return true;

} else {

return false;

}

}

/**

*

* You may assume that the input array (String[] candidates) will

* not be null or empty.

*

* @param first - first valid id

* @param last - last valid id

*

* A ballot is valid if it is: filled, time-stamped,

* and have an official id and a vote for one of the candidate listed

*

* @return true if the Ballot is valid based on the criteria listed above,

* false otherwise

*/

public boolean isValid(int first, int last, String[] candidates) {

if(this.id <= last && this.id >= first) {

if(this.timestamp != null && this.filled == true) {

for(String valid: candidates) {

if(this.candidate.equals(valid)) {

return true;

}

}

}

}

return false;

}

}

PUBLIC CLASS EMPTYBALLOT which create empty ballot for the function

public class EmptyBallots {

public Ballot head;

*

* Create list with n empty ballots, with id from 0 to n-1

*

* @param n - the number of empty ballots to create in the list

*/

public EmptyBallots(int n) {

int data[] = new int[n];

for(int x = 0; x < data.length; x++) {

Ballot empty = new Ballot(0, head);

head = empty;

empty.id = (n-x)-1;

head.id = empty.id;

}

}

/** 5 marks - Pass level

*

* Remove the first empty ballot from the list

*

* @return the removed ballot if there are still empty ballots

* left in the list, null otherwise

*/

public Ballot remove() {

if(head == null) {

return null;

}

Ballot removed = head;

head = head.next;

return removed;

}

public boolean isValid() {

if (head == null) {

return true;

}

Ballot current = head;

while (current.next != null) {

if (current.id + 1 != current.next.id) {

return false;

}

current = current.next;

}

return true;

}

}

how to make my addVote function more efficient

/**

*

*

* Add a vote (a ballot) for a candidate to the END of the Filled list.

*

* @param candidate - the name of the candidate voted for

* @param ballots - the list of empty ballots where the official card comes from

* @param a new time stamp

*

*/

FUNCTION

public void addVote(String candidate, EmptyBallots ballots, Timestamp time) {

Ballot now = head;

Ballot filled = ballots.remove();

if (filled != null) {

filled.fill(candidate, time);

}

if (head == null) {

filled.id = id;

head = filled;

filled.next = null;

id++;

return;

}

while (now.next != null) {

now = now.next;

id++;

}

now.next = filled;

id++;

filled.next = null;

}

Normal expected output (I pass it)

@Test

@Order(6)

@Timeout(1)

public void testFilledBallotsAddVote() {

assertTimeoutPreemptively(Duration.ofMillis(1000), () -> {

EmptyBallots e;

FilledBallots f;

// Case 1: Add one ballot

e = new EmptyBallots(100);

f = new FilledBallots();

assertNull(f.head);

f.addVote(candidates[0],e,new Timestamp());

assertNotNull(f.head);

assertEquals(candidates[0],f.head.candidate);

// Case 2: Add multiple ballots

e = new EmptyBallots(100);

f = new FilledBallots();

assertNull(f.head);

f.addVote(candidates[0],e,new Timestamp());

f.addVote(candidates[1],e,new Timestamp());

f.addVote(candidates[2],e,new Timestamp());

f.addVote(candidates[0],e,new Timestamp());

f.addVote(candidates[2],e,new Timestamp());

assertNotNull(f.head);

assertEquals(candidates[0],f.head.candidate);

assertEquals(candidates[1],f.head.next.candidate);

assertEquals(candidates[2],f.head.next.next.candidate);

assertEquals(candidates[0],f.head.next.next.next.candidate);

assertEquals(candidates[2],f.head.next.next.next.next.candidate);

assertNull(f.head.next.next.next.next.next);

});

currentMethodName = new Throwable().getStackTrace()[0].getMethodName();

}

@Test

@Order(12)

@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)

public void testFilledBallotsAddVoteAdvanced() {

// Case 1: Medium size

assertTimeoutPreemptively(Duration.ofMillis(1000), () -> {

EmptyBallots e = new EmptyBallots(mLimit);

FilledBallots f = new FilledBallots();

for(String s : testcase3) {

f.addVote(s, e, new Timestamp());

}

assertNotNull(f);

Ballot cur = f.head;

for(int i = 0; i < 200; i++) cur = cur.next;

assertEquals(candidates[4],cur.candidate);

assertEquals(candidates[0],cur.next.candidate);

assertEquals(candidates[4],cur.next.next.candidate);

for(int i = 0; i < 500; i++) cur = cur.next;

assertEquals(candidates[3],cur.candidate);

assertEquals(candidates[3],cur.next.candidate);

assertEquals(candidates[0],cur.next.next.candidate);

});

// Case 2: Large size

assertTimeoutPreemptively(Duration.ofMillis(1000), () -> {

EmptyBallots e = new EmptyBallots(xLimit);

FilledBallots f = new FilledBallots();

for(String s : testcase5) {

f.addVote(s, e, new Timestamp());

}

assertNotNull(f);

Ballot cur = f.head;

for(int i = 0; i < 200000; i++) cur = cur.next;

assertEquals(candidates[2],cur.candidate);

assertEquals(candidates[2],cur.next.candidate);

assertEquals(candidates[4],cur.next.next.candidate);

for(int i = 0; i < 500000; i++) cur = cur.next;

assertEquals(candidates[0],cur.candidate);

assertEquals(candidates[3],cur.next.candidate);

assertEquals(candidates[2],cur.next.next.candidate);

});

currentMethodName = new Throwable().getStackTrace()[0].getMethodName();

}

Write program that dynamically allocates an array in the freestore large enough to hold a user defined number of test scores as doubles. Once all the scores are entered, the array should be passed to a function that finds the highest score. Another

Write program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Design the following functions in the program: calcAverage

Write a correct and complete C++ program that inputs 20 integer values from the user and performs three calculations. In the main function, input the values from the user

Write program that reads a sequence of integers into an array and that computes the alternating sum of all elements in the array.

all questions needs to be answered

This question addresses the problem of colouring the following graph using a constraint satisfaction approach. 1 2 5 3 4 6 7 The colours available are amber, black and crimson which we will denote by A, B and C respectively. We want to assign a colour to each node in the graph in such a way that if there is an edge (n1, n2) between any pair of nodes then n1 and n2 have different colours. (a) Explain how this problem can be represented as a constraint satisfaction problem. [2 marks] (b) Explain how we can apply forward checking in the process of solving a constraint satisfaction problem. Illustrate your answer using the above graph colouring problem where the initial steps are, in order, 1 = A, 2 = B, 6 = B, 5 = C. In particular, you should show how the process can reduce branching and induce backtracking. [8 marks] (c) Explain how we can apply constraint propagation using arc consistency in the process of solving a constraint satisfaction problem. Illustrate your answer using the same initial steps in the same order. Determine whether or not backtracking occurs earlier in this case and explain why. [10 marks] 2 CST.2010.4.3 2 Artificial Intelligence I Evil Robot's creator has sent him on a mission. He must go to the Secret Mountain Hideout, put on an orange boiler suit so that he blends in, then pick up two items called Component 1 and Component 2 and join them together. Finally, he has to press the BIG RED BUTTON (which only works when the two components are joined together) in order to cause something horrible to happen. Evil Robot's internal systems have been constructed using the situation calculus and a theorem prover. (a) Give a brief outline of the situation calculus, concentrating on the fundamental elements that you would expect to see independently of any specific problem. [4 marks] (b) Suggest three logical formulae that might appear in Evil Robot's knowledge base in order to describe the initial state for the above problem.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Financial Accounting

Authors: Theodore E. Christensen, David M. Cottrell, Richard E. Baker

10th edition

78025621, 978-0078025624

More Books

Students also viewed these Computer Network questions

Question

What general trade-off is involved in waiting-line decisions?

Answered: 1 week ago