Crash Consensus Algorithm - java

I am having problems implementing the Crash Consensus Algorithm.
Here is some pseudo code. Can someone please give me a an explanation on what it means.
Crash-Consensus-Receive-Message(m)
if m is proposal message then
▷add the received values to set of all known proposed values
add[knownValues,values[m]]
note that sender[m]has not crashed during this round
else ▷ordinary message received
process message m
Crash-Consensus-Reach-Consensus()
knownValues←{ownValue} ▷start with just own proposed value
sentValues←0 ▷no values sent yet
for i←0 to f do ▷f+1 rounds of multicasts
▷determine which known values have not yet been sent
newValues←knownValues -ssentValues
multicast proposal message with newValues to alive processes
wait until next round
use pre-agreed strategy with knownValues to get consensus value
What does it mean by sender[m] and values[m] as the m means message here? Also what does it mean by knownValues.

In the most of programming languages the square brackets mean an array of values, in your case an array of knowed messages or an array of messeges to send. I'm not sure if this is also true in pseudo code but I think maybe can help you in all case.

Related

Can't get any CPU or memory value with SNMP

I'm trying to get CPU and memory usage with SNMP. I have a Java code which takes the oid and runs the "get" command. I can reach the values with MIB-II. However when i import HOST-RESOURCES-MIB in the code i can't get CPU information it returns Null. But some oids work properly in HOST-RESOURCES-MIB.
For example:
hrSystemUpTime(.1.3.6.1.2.1.25.1.1.0) gives me the value 3:51:15.07
hrProcessorLoad(.1.3.6.1.2.1.25.3.3.1.2.0) gives me the value Null
What is the problem?
I've solved the problem. In MIBs the information kept in indexes. Thus, in order to reach a particular information, you need to know which index it's kept.So, i did SNMPWalk on .1.3.6.1.2.1.25.3.3.1.2 for hrProcessorLoad (omit zero) and i got the values. We can also use getNext command to reach the correct index.

Throw exception or return a crazy value when input is bad, but might be common?

I have a class that analyzes and interprets GPS strings. The incoming strings are formatted in a very specific way (15 comma separated strings/values). Right now, if I receive a string that is not expected (like if it doesn't have 14 commas), I am throwing an IllegalArgumentException. This is for the cases when the incoming string is truly broken and this event should rarely, if ever happen.
However, if my GPS unit has not connected to the satellite yet, I will receive blank values between the commas. How can I return something that tells the user "The GPS isn't turned on yet," without returning Null? In my particular case, returning Null is something that is already needed. I thought of returning some insane value that can be checked against, but this seems like really sloppy program design to me. What would a good method for a situation like this be?

Transformation algorithms for numerical values similar to functionality of Soundex, Metaphone, etc

I'm working on implementing probablistic matching for person record searching. As part of this, I plan to have blocking performed before any scoring is done. Currently, there are a lot of good options for transforming strings so that they can be stored and then searched for, with similar strings matching each other (things like soundex, metaphone, etc).
However, I've struggled to find something similar for purely numeric values. For example, it would be nice to be able to block on a social security number and not have numbers that are off or have transposed digits be removed from the results. 123456789 should have blocking results for 123456780 or 213456789.
Now, there are certainly ways to simply compare two numerical values to determine how similar they are, but what could I do when there are million of numbers in the database? It's obviously impractical to compare them all (and that would certainly invalidate the point of blocking).
What would be nice would be something where those three SSNs above could somehow be transformed into some other value that would be stored. Purely for example, imagine those three numbers ended up as AAABBCCC after this magical transformation. However, something like 987654321 would be ZZZYYYYXX and 123547698 would be AAABCCBC or something like that.
So, my question is, is there a good transformation for numeric values like there exists for alphabetical values? Or, is there some other approach that might make sense (besides some highly complex or low performing SQL or logic)?
The first thing to realize is that social security numbers are basically strings of digits. You really want to treat them like you would strings rather than numbers.
The second thing to realize is that your blocking function maps from a record to a list of strings that identify comparison worthy sets of items.
Here is some Python code to get you started. (I know you asked for Java, but I think the Python is clear and you aren't paying me enough to write it in Java :P ). The basic idea is to take your input record, simulate roughing it up in multiple ways (to get your blocking keys), and then group on by any match on those blocking keys.
import itertools
def transpositions(s):
for pos in range(len(s) - 1):
yield s[:pos] + s[pos + 1] + s[pos] + s[pos + 2:]
def substitutions(s):
for pos in range(len(s)):
yield s[:pos] + '*' + s[pos+1:]
def all_blocks(s):
return itertools.chain([s], transpositions(s), substitutions(s))
def are_blocked_candidates(s1, s2):
return bool(set(all_blocks(s1)) & set(all_blocks(s2)))
assert not are_blocked_candidates('1234', '5555')
assert are_blocked_candidates('1234', '1239')
assert are_blocked_candidates('1234', '2134')
assert not are_blocked_candidates('1234', '1255')

Compare strings that can come in a different internal order

I'm writing a JUnit test that check messages (one message per line) inside one unified String. The format is as follows:
[* Message for Alice *]
Hey, first message
Second message
[* Message for Jim *]
Holler
Are you there?
[* General Messages *]
Welcome everyone!
This is yet another message.
The problem is that the actual string's order that I receive may change (except for the General Messages that always comes at the end of the string). For example: one time I can get Jim's messages first, so when I try to use assertEquals() the test fails. Unfortunately I don't have access to the code that generate the messages, so I can't make any modifications.
What is the best way to compare these strings and validate that they're the same?
You should re-organize your tests to address arbitrary re-ordering, for example, like this:
Split the string into individual messages
Separate general messages and all other messages
Order expected and actual messages in the same order (e.g. alphabetical)
Compare ordered lists of expected and actual messages. Now that they are ordered the same, they should equal item-by-item
Check that the general messages come after all other messages in the actual message stream.
You'd better compare Sets of messages, as the fuzzy string comparison you're after is going to be too tricky...

C sockets - randomly receiving more than one string at a time

I have encountered an interesting C sockets problem.
I am receiving incoming strings and noticed that I will, randomly, receive 3 strings at a same time for the first 2 ~ 4 strings.
For example, I am receiving the following incoming strings.
1~message~i love you\r\n
2~message~do you love me?\r\n
3~message~when are we going to meet again?\r\n
4~message~How about now?\r\n
5~message~Oh! I'm pregnant!\r\n
I added a counter to track the number of messages received and noticed that the counter sometimes does not count the first 3 strings. For example
1~message~i love you\r\n
->Line 1 received
2~message~do you love me?\r\n
3~message~when are we going to meet again?\r\n
4~message~How about now?\r\n
->Line 2 received
5~message~Oh! I'm pregnant!\r\n
->Line 3 received
The following is my code for printing the line number
int lineNo = 1;
while ((recvBytes = recv(clntSockfd, buffer, sizeof(buffer), 0)) > 0) {
printf("%s", buffer);
memset(&buffer, 0, sizeof(buffer));
printf("Line %d received\n", lineNo++);
}
I'm not sure why is this happening since this problem did not appear when i coded in Java nio.
Any ideas, folks?
Assuming you are using TCP, relating recv() calls to "messages" (or "lines") in your case is flawed. TCP, conceptually, is a stream of bytes. The sending operating system is free to group multiple send() calls into a single IP packet, as is the receiving operating system free to report multiple incoming packets as a single recv() call (assuming the buffer is large enough). It may even choose to split an incoming packet across recv calls.
So you really need to put a message structure in the data itself, eg. by scanning for line breaks in the data received.
That this didn't occur in Java was pure luck.
You are not reading till end of line. The buffer can contain more than one line.
what connection type are you using?
UDP is unreliable most of the time.
TCP is much better than UDP in terms of reliability.

Categories